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贡献2011条经验 获得超2个赞
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贡献2012条经验 获得超12个赞
您不需要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
提交
取消
