[英]C# and Linq to Entities using count in a where lambda statement
[英]using a IF type statement in a linq to entities SELECT NEW clause C#
我從2個表中返回數據,一個表包含停止信息,另一個表包含傳遞信息。 可能有一個停頓而沒有交付,或者有多次交付。
我要返回一個數據網格,我想要一列顯示記錄是停止還是停止交付。
如果記錄沒有交付(為空),則當前查詢在deliveryID字段中返回“ 0”。
我想添加另一個名為rowType的字段,其中,如果deliveryID = 0,它將返回“僅停止”的值,如果返回“停止並交付”,則以下代碼將正常工作,但沒有新字段。
var combinedEvents = (from d in dbContext.stop_details
join s in dbContext.stop_event on d.id equals s.stop_id into Inners
from sd in Inners.DefaultIfEmpty()
where (d.ship_date >= startDate && d.ship_date <= endDate)
select new
{
deliveryID = (int?)sd.id ?? 0,
stopID = d.id,
d.ship_date,
d.cust_ref_1_BOL,
d.cust_ref_2_OrderNum,
sd.received_by
}).ToList();
我可以這樣做嗎?
使用條件?
運算符,然后復制您的邏輯deliveryID
:
rowType = ((int?)sd.id).HasValue ? "Stop With Delivery" : "Stop Only"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.