我有可查询数据时间字段的linq查询,该字段根据条件填充值.
var result=(from t1 in context.table1
join t2 in context.table2
on t1.id equals t2.fieldId
select new model1
{
name= t2.name,
DateCompleted = t1.Status == "Success"
? Convert.ToDateTime(t1.CompletedDate)
: Null
}).ToList();
Run Code Online (Sandbox Code Playgroud)
这里DateCompleted可以为空.如果状态成功那么我只需要完成日期.其他明智的我需要显示null.现在":Null"部分抛出错误.
谢谢Subin