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();
其他写法