连接

pcww981p  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(242)

早上好,
我正在尝试使用ef.net(不是core)和linq让一个3表连接工作,但是我的一生都不能得到我期望的结果。
场景:我们有一个网页,人们在其中执行查找,这些用户没有登录,但他们的ip地址记录在查找中。
数据库:帐户(包含accountid、公司名称、emailaddress)查找(包含ipaddress、searchresult、datesearched)ipaddress(包含accountid、ipaddress)
要求:我一直在尝试创建一个查询,在那里我向它传递accountid,它告诉我帐户根据他们搜索的ipaddress进行了多少次查找。
尝试的代码:下面的代码和我想的一样接近,但仍然没有返回结果

public int getLookups(int accountID)
{
        var query = (from p in mySqlEntities.individual_lookups
                    join meta in mySqlEntities.ip_addresses on p.ipAddress equals meta.ip_address
                    where p.accountID == accountID
                    select p.id).Count();
        return query;
}

我不太清楚我在这里哪里出了问题,但在这件事上任何帮助都将不胜感激。谢谢您!

jobtbby3

jobtbby31#

如果我读对了你的问题,那么这些是你的table
数据库:帐户(包含accountid、公司名称、emailaddress)查找(包含ipaddress、searchresult、datesearched)ipaddress(包含accountid、ipaddress)
也就是说 mySqlEntities.individual_lookups 没有一个 accountId 列,但你的 mySqlEntities.ip_addresses 做。
将where子句改为下面的内容,看看是否还有进一步的内容:

where meta.accountID == accountID

相关问题