【发布时间】:2013-12-23 07:04:37
【问题描述】:
invoiceData = from x in context.PdtDeliveryTables
join pt in context.DiagramNoTables on x.DiagramID equals pt.DiagramID
join mt in context.MaterialTables on pt.MaterialID equals mt.MaterialID into t from ct in t.DefaultIfEmpty()
join odr in context.OrderTables on x.OrderID equals odr.OrderID into sr
from d in sr.DefaultIfEmpty()
where (pt.CustomerID == customerID) && (x.DeliveryDate >= (startDate ?? DateTime.MinValue) && x.DeliveryDate <= (endDate ?? DateTime.MaxValue))
orderby x.DeliveryDate ascending
select new InvoiceTable
{
};
我需要在 OR 条件下替换这个左连接条件:
join odr in context.OrderTables on x.OrderID equals odr.OrderID into sr
from d in sr.DefaultIfEmpty()
喜欢:
join odr in context.OrderTables on x.OrderID equals
x => x.OrderID !=0
? x.OrderNo
: x.DeliveryNo
into sr from d in sr.DefaultIfEmpty()
- 以下是更改后的查询,但仍然出现超时异常
-
超时。在操作完成之前超时时间已过或服务器没有响应。
invoiceData = from x in context.PdtDeliveryTables join pt in context.DiagramNoTables on x.DiagramID equals pt.DiagramID join mt in context.MaterialTables on pt.MaterialID equals mt.MaterialID into t from ct in t.DefaultIfEmpty() from d in context.OrderTables.DefaultIfEmpty() where (x.OrderID != 0 && x.OrderID == d.OrderID) || (x.OrderID == 0 && x.DeliveryNo == d.OrderNo) where (pt.CustomerID == customerID) && (x.DeliveryDate >= (startDate ?? DateTime.MinValue) && x.DeliveryDate <= (endDate ?? DateTime.MaxValue)) orderby x.DeliveryDate ascending select new InvoiceTable { OrderID = x.OrderID, OrderNo = x.OrderID != 0 ? d.OrderNo : x.DeliveryNo, DiagramNo = pt.DiagramNo, ProductName = pt.ProductName, MaterialName = ct.MaterialName, Quantity = x.DeliveryQty, OrderDate = x.DeliveryDate, InvoiceDate = d.InvoiceDate, UnitPrice = d.UnitPrice != null ? d.UnitPrice : pt.SellingPrice, Amount = d.UnitPrice != null ? d.UnitPrice * x.DeliveryQty : pt.SellingPrice * x.DeliveryQty, Printable = true }; }
【问题讨论】:
-
@Soner 感谢编辑...!!!
标签: c# linq c#-4.0 linq-to-entities