UseDatabaseNullSemantics still generating NULL checks

前端 未结 2 1317
失恋的感觉
失恋的感觉 2021-01-14 15:16

I have this on my context object (constructor):

this.Configuration.UseDatabaseNullSemantics = true;

But even with this set, this query:

相关标签:
2条回答
  • 2021-01-14 15:39

    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();
    
    0 讨论(0)
  • 2021-01-14 15:50

    The condition you see inside the generated SQL has nothing in common with UseDatabaseNullSemantics and is needed to handle correctly LEFT LOINs 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.

    0 讨论(0)
提交回复
热议问题