I have this on my context object (constructor):
this.Configuration.UseDatabaseNullSemantics = true;
But even with this set, this query:
Does this work? If the posted query is correct when you remove the (or (is null and is null)) clause, then I think this will execute the same query. (This assumes there isn't a logic error in the joins, as suggested in other posts.)
var query = (from i in _repo.Invoices
from o in _repo.Orders.Where(c => c.orderid == i.orderid)
from o2 in _repo.Orders.Where(c => c.linkedorderid == o.linkedorderid).DefaultIfEmpty()
where invoiceIds.Contains(i.invoiceid)
select new
{
i, o2
}).ToList();
The condition you see inside the generated SQL has nothing in common with UseDatabaseNullSemantics
and is needed to handle correctly LEFT LOIN
s with nullable keys.
I think the problem you are experiencing is caused by a logical error in your query. IMO, the join condition
on o.linkedorderid equals o2.linkedorderid
should be
on o.linkedorderid equals o2.orderid
because normally the FK relates (joins) to the PK.