0
我从2个表中返回数据,其中一个包含停止信息,另一个包含传递信息。可以有一个停止没有交付,或多次交付。在LINQ中使用IF类型语句来实体SELECT NEW子句C#
我回到了一个数据网格,我想要一列显示记录是停止还是停止交付。
如果记录没有递送(为空),我当前的查询在deliveryID字段中返回'0'。
我想要添加另一个称为rowType的字段,如果deliveryID = 0,它将返回“Stop Only”的值,如果有其他内容,则返回“Stop with Delivery” 以下代码正常工作,但没有新字段。
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();
我可以这么做么?
像'ROWTYPE =((int)的sd.id?).HasValue? “停止交货”:“只停止”'也许? –
我一直试图做到这一点,但忘了投(int?),所以我的HasValue不会出现。谢谢伙伴...如果你想写出来作为答案,我会接受它。 –