Linq到SQL左转外部联接此查询是否等效于LEFT OUTER加入?//assuming that I have a parameter named 'invoiceId' of type intfrom c in SupportCaseslet invoice = c.Invoices.FirstOrDefault(i=> i.Id == invoiceId)where (invoiceId == 0 || invoice != null) select new {
Id = c.Id
, InvoiceId = invoice == null ? 0 : invoice.Id}
3 回答
翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
SelectManyDefaultIfEmpty
var query = from c in db.Customers
join o in db.Orders
on c.CustomerID equals o.CustomerID into sr from x in sr.DefaultIfEmpty()
select new {
CustomerID= c.CustomerID, ContactName=c.ContactName,
OrderID = x.OrderID == null ? -1 : x.OrderID};(或者通过扩展方法)
凤凰求蛊
TA贡献1825条经验 获得超4个赞
您不需要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添加回答
举报
0/150
提交
取消
