此查询是否等同于 LEFT OUTER
联接?
//assuming that I have a parameter named 'invoiceId' of type int
from c in SupportCases
let invoice = c.Invoices.FirstOrDefault(i=> i.Id == invoiceId)
where (invoiceId == 0 || invoice != null)
select new
{
Id = c.Id
, InvoiceId = invoice == null ? 0 : invoice.Id
}
最佳答案
您不需要 into 语句:
var query =
from customer in dc.Customers
from order in dc.Orders
.Where(o => customer.CustomerId == o.CustomerId)
.DefaultIfEmpty()
select new { Customer = customer, Order = order }
//Order will be null if the left join is null
是的,上面的查询确实创建了一个 LEFT OUTER 连接。
链接到处理多个左连接的类似问题: Linq to Sql: Multiple left outer joins
关于.net - LINQ to SQL 左外连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/700523/