我想在下面的LINQ语句中弄清楚我做错了什么。它不喜欢第三个SELECT
。当我输入查询时,它会在Intelisense中找到tblAddresse.tblAdminCounty
,但是当我输入SELECT之后它就会发现它。
是否与tblAddress
和tblAdminCounty
有关?我认为它在tblAddress
下的Intellisense中显示的事实会使这一陈述不言而喻,但显然不是。
如果我只是在单独的函数中查询CountyName,它将看起来像这样 - >
var countyName = from adminCounty in context.tblAdminCounties
where adminCounty.CountyID == countyID
select adminCounty.CountyName;
这是基于此网站的更大的3层方法 - > HERE
var query = from tblBusinesse in context.tblBusinesses
where tblBusinesse.BusinessID == businessID
select new
{
tblBusinesse.BusinessName,
tblBusinesse.ContactName,
tblBusinesse.EmailAddress,
Address = from tblAddresse in tblBusinesse.tblAddresses
select new
{
tblAddresse.AddressLine1,
tblAddresse.AddressLine2,
tblAddresse.AddressLine3,
tblAddresse.CityName,
County = from adminCounty in tblAddresse.tblAdminCounty
select new
{
adminCounty.CountyName
}
}
};
答案 0 :(得分:2)
您尝试查询它,就好像一个地址有多个县一样。它被称为tblAdminCounty
而不是tblAdminCounties
的事实是否表明它只是一个项目?
尝试更改此内容:
County = from adminCounty in tblAddresse.tblAdminCounty
select new
{
adminCounty.CountyName
}
只是:
County = tblAddresse.tblAdminCounty