title: Left join using LINQ with Entity Framework Core
body: <p>When I try to join multiple tables by using .net core with Entity Framework Core, I'm getting the following error:</p>
  
  <blockquote>
    <p>Operation is not valid due to the current state of the object </p>
    
    <p>at System.Linq.Expressions.MethodCallExpression1.GetArgument(Int32 index)<br>
    at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.QueryFlattener.Flatten(MethodCallExpression methodCallExpression)</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>var userBasicInfo = (from ubi in idamDbContext.UserBasicInfo
                       join c in idamDbContext.Center on ubi.CenterId equals c.Id
                       join t in idamDbContext.Territory on ubi.TerritoryId equals t.Id
                       join r in idamDbContext.Registration on ubi.UserId equals r.UserId                                 
                       into parent
                       from p in parent.DefaultIfEmpty()
                       where ubi.SsdsId == ssdsId
                       select new
                           {
                               BirthDate = ubi.Birthdate,
                               CenterId = ubi.CenterId,
                               Email = ubi.Email,
                               FirstName = ubi.FirstName,
                               LastName = ubi.LastName,
                               Login = ubi.UserName,
                               SSDSRefId = ubi.SsdsId,
                               TerritoryId = ubi.TerritoryId,
                               UserId = ubi.UserId,
                               Gender = ubi.Gender,
                               UserTypes = ubi.UserId,
                               ContractID = p.ContractId,
                               CenterRefID = c.ReferenceCenterId,
                               CenterName = c.Name,
                               CountryRefID = t.ReferenceTerritoryId
                           }).FirstOrDefault();
  </code></pre>
  
  <p>I have to get data from the above four tables whether the ContractId exists from the Registration table or not. If exists it'll return an entire data or else ContractId should be return null.</p>
  
  <p>Could you please share your thoughts if you anyone have an idea?</p>
  
  <p>Thanks,
  Parthiban. </p>