How to Use Navigation Property generate left join sql not inner join sql
See original GitHub issueWhen Use Navigate Property one to one:
Normally the sql is a inner join , I do not know how to write a left Join use one to one Navigate Property
usually,we can also use Include to make ef generate a left join sql ,there is other method?
I donot like linq like this:
var LeftJoin = from a in aList
join b in bList on a.Id equals b.Id into cc
from b in cc.DefaultIfEmpty()
can implent like this?
_context.Doctor.where(t=>t.Id==id)
.Select(doctor => new DoctorDTO()
{
Name=doctor.Name,
HospitalName=doctor.Hospital.Name // want left join not innner join
}
In project ,i use automapper ProjectTo< DTO >,but how can i use One to One Navigation property generate left join sql?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
EF Core Navigation Property Include uses Left Join instead ...
I can see on my SQL Server Profiler a left join rather than an inner join. I tried removing the annotations and going...
Read more >Join Query In Entity Framework
The above code creates the following SQL Query. The EF efficiently decides INNER JOIN & LEFT JOIN based the navigational property. 1. 2....
Read more >Complex Query Operators - EF Core
The LINQ Join operator allows you to connect two data sources based on the key selector for each source, generating a tuple of...
Read more >Don't use Linq's Join. Navigate! | Passion for Coding
Don't use Linq's Join. Navigate! ... One of the greatest benefits of LINQ to SQL and LINQ to Entities is navigation properties that...
Read more >How to Use Entity Framework Left Join?
Entity Framework Left Join is a database-oriented process that joins the data from two or more tables using a join query.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ByZhouhang AFAIK EF Core does not generate RIGHT JOIN - it would be a bit difficult to imagine the LINQ that would be used to express such a query; you’ll have to start your LINQ query from UserAnswer. Note that RIGHT JOINs are mathematically rewritable as LEFT JOINs. Do you have any particular reason to want to start with UserAnswer rather than TrialQuestion, or is a matter of personal preference?
@ByZhouhang as with your first code sample (Doctor and Hospital), if you make UserAnswer.TrialQuestionId nullable, EF Core will produce a LEFT JOIN, since a UserAnswer might not have a TrialQuestion; the “requiredness” of navigations is determined by the nullability of their foreign keys, and that’s what determines whether an INNER or LEFT join is used.
EF Core doesn’t generate RIGHT JOIN, but these are logically the same as LEFT JOIN.