首页 新闻 会员 周边 捐助

EF core Linq Left Join 问题

0
悬赏园豆:15 [已关闭问题] 关闭于 2021-07-09 13:31

之前用的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
};

忧虑的心的主页 忧虑的心 | 初学一级 | 园豆:73
提问于:2021-07-09 12:06
< >
分享
所有回答(1)
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?

忧虑的心 | 园豆:73 (初学一级) | 2021-07-09 13:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册