LINQ One for many, 3 levels Deep question

I am trying to figure out what I am doing wrong in the bottom LINQ expression. He does not like the third SELECT. It finds tblAddresse.tblAdminCountyin Intelisense when I type a query, but when I type SELECT after it's ugly.

Is this related to how tblAddressand are related tblAdminCounty? I would think that the fact that he shows in Intellisense under tblAddresswill make this statement for granted, but clearly not.

If I only requested the county name in a separate function, it would look like this:>

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

And this is a larger three-tier approach based on this site → 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
                                   }

                      }
            };
+3
1

, . , tblAdminCounty, tblAdminCounties, , ?

:

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

:

County = tblAddresse.tblAdminCounty
+2

Source: https://habr.com/ru/post/1730594/


All Articles