3

我试图找出我在下面的 LINQ 语句中做错了什么。它不喜欢第三个SELECTtblAddresse.tblAdminCounty当我输入查询时 它会在 Intelisense 中找到,但是当我在它之后输入 SELECT 时它会发疯。

它与如何相关tblAddresstblAdminCounty相关吗?我原以为它在 Intellisense 下显示的事实tblAddress将使该声明不言自明,但显然不是。

如果我只是在单独的函数中查询 CountyName,它看起来像这样 -->

var countyName = from adminCounty in context.tblAdminCounties
                 where adminCounty.CountyID == countyID
                 select adminCounty.CountyName;

这是基于此站点的更大的 3 层方法 -->这里

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
                                   }

                      }
            };
4

1 回答 1

2

您正在尝试查询它,就好像一个地址有多个县一样。它被称为tblAdminCounty而不是tblAdminCounties暗示它只是一个项目的事实不是吗?

尝试改变这个:

County = from adminCounty in tblAddresse.tblAdminCounty
         select new
         {
             adminCounty.CountyName
         }

只是:

County = tblAddresse.tblAdminCounty
于 2010-01-29T21:25:05.907 回答