Left external link to the core of the Entity Framework

I am trying to query an external external connection with EF7 (7.0.0-rc1-final), vNext RC1 (rc1-final) and SQL Server 2014

Database:

Pet: Id, Name

User: Id, Name, #PetId

It works:

var queryWorks = from u in _context.Users
                 join p in _context.Pets on u.PetId equals p.Id into pp
                 from p in pp.DefaultIfEmpty()
                 select new {
                     UserName = u.Name,
                     Pet = p
                 };

but this one does not work (Message = "Sequence contains no elements"):

var queryFails = from u in _context.Users
                 join p in _context.Pets on u.PetId equals p.Id into pp
                 from p in pp.DefaultIfEmpty()
                 select new {
                     UserName = u.Name,
                     PetName = (p == null ? "NULL" : p.Name)
                 };

The SQL Server 2014 profile shows that the second query is not sent to SQL Server. Why?

+4
source share
1 answer

I think this is yours p.Namewithin the projection of your second request, which is not being processed.

RC1, EF7 , . , , , , .

issue 3186 github, .

, .

"maumar" :

, Linq ( ) LOJ .

SelectMany-GroupJoin-DefaultIfEmpty LOJ . , ( - ) . , .

, .

+3

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


All Articles