小可爱

ef 两表left join

电脑版发表于:2019/10/21 9:53


linq写法:

//linq写法
var query = (from u in oae.Users
                join p in oae.User_Parent on u.Id equals p.UsersId into jointemp
                from leftjoin in jointemp.DefaultIfEmpty()
                select new UserViewModel
                {
                    UserName = u.UserName,
                    Father = leftjoin.Father,
                    Mother = leftjoin.Mother
                }).ToList();

lamdba写法:

//lamdba
var result = oae.Users.GroupJoin(oae.Score, a => a.Id, b => b.UsersId, (a, b) => new
                            {
                                UserName = a.UserName,
                                scoreList = b
                            }).SelectMany(a => a.scoreList.DefaultIfEmpty(), (a, b) => new
                            {
                                UserName = a.UserName,
                                Sub = b.Sub,
                                Score = b.Score1
                            }).ToList();


其他写法




关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢