I am trying to get a left join working in Linq using ASP.NET Core and EntityFramework Core.
Simple situation with two tables:
You not doing left join, the linq which you are using is basically creating a inner join. For left join in linq use into keyword
[HttpGet]
public IActionResult Get()
{
var result = from person in _dbContext.Person
join detail in _dbContext.PersonDetails on person.Id equals detail.PersonId
into Details
from defaultVal in Details.DefaultIfEmpty()
select new
{
id = person.Id,
firstname = person.Firstname,
lastname = person.Lastname,
detailText = defaultVal.DetailText
};
return Ok(result);
}