之前用的ef,用bjoin.Any()来判断是否为空都没问题,ef core为啥就不行了,一直报Nullable object must have a value
代码如下:
var ret = from x in query
join b in taskQuery on x.NewID equals b.FunctionId into bjoin
from bj in bjoin.DefaultIfEmpty()
select new ProjectFunc_View
{
ID = x.ID,
PlanWorkload = x.PlanWorkload,
FuncName = x.FuncName,
FuncMark = x.FuncMark,
ProjectName_view = x.ProjectName_view,
ProjectId = x.ProjectId,
CreateBy = x.CreateBy,
CreateTime = x.CreateTime,
WorkHours =bjoin.Any()? bj.WorkHours:0
};
正确代码:
var ret = from x in query
join b in taskQuery on x.NewID equals b.FunctionId into bjoin
from bj in bjoin.DefaultIfEmpty()
select new ProjectFunc_View
{
ID = x.ID,
PlanWorkload = x.PlanWorkload,
FuncName = x.FuncName,
FuncMark = x.FuncMark,
ProjectName_view = x.ProjectName_view,
ProjectId = x.ProjectId,
CreateBy = x.CreateBy,
CreateTime = x.CreateTime,
WorkHours = bj.WorkHours
};
WorkHours 设置为double?