我有很多表格,如:
我需要的是用户信息
我到目前为止能够做到以下但是我遇到了麻烦1)在lamda表达式中间我是如何做的(IsWorking == true)并且继续加入到下一个表。以下是我的表达
List<Models.UserInfo> v = context.User_cs
.Join(context.UserEducation_cs, u => u.UserName, ue => ue.UserName, (u, ue) => new UserEducation_cs
{
UserName = ue.UserName,
EducationId = ue.EducationId,
StartDate = ue.StartDate,
EndDate = ue.EndDate
}).
Join(context.Education_cs, ue => ue.EducationId, e => e.EducationId, (ue, e) => new
{
UserName = ue.UserName,
EducationId = ue.EducationId,
StartDate = ue.StartDate,
EndDate = ue.EndDate,
Title = e.Title,
Major = e.Major,
MajorDetails = e.MajorDetails,
Info = e.Info
}).
Join(context.Experiences, lst => lst.UserName, ex => ex.UserName, (lst, ex) => new Models.UserInfo
{
UserName = ex.UserName,
EducationId = lst.EducationId,
StartDate = lst.StartDate,
EndDate = lst.EndDate,
Title = lst.Title,
Major = lst.Major,
MajorDetails = lst.MajorDetails,
Info = lst.Info,
IsWorking = ex.IsWorking,
StartDate_ex=ex.StartedDate,
}).
Where(iw => iw.IsWorking == true).ToList();
任何帮助将不胜感激
答案 0 :(得分:1)
我不完全确定我是否完全理解你的问题。我认为您需要在将(内部)联接应用于它们之前过滤您的列表。要为每个Education_cs
仅获取最新的User_cs
条目,我想您可以使用分组。另外,我还没有完全测试过这段代码:
List<Models.UserInfo> v = context.User_cs
.Join(context.UserEducation_cs, u => u.UserName, ue => ue.UserName, (u, ue) => new UserEducation_cs
{
UserName = ue.UserName,
EducationId = ue.EducationId,
StartDate = ue.StartDate,
EndDate = ue.EndDate
}).
Join(context.Education_cs.GroupBy(q => q.UserName).Select(q => q.OrderByDescending(w => w.StartDate).First()),
ue => ue.EducationId, e => e.EducationId, (ue, e) => new
{
UserName = ue.UserName,
EducationId = ue.EducationId,
StartDate = ue.StartDate,
EndDate = ue.EndDate,
Title = e.Title,
Major = e.Major,
MajorDetails = e.MajorDetails,
Info = e.Info
}).
Join(context.Experiences.Where(ex => ex.IsWorking), lst => lst.UserName, ex => ex.UserName, (lst, ex) => new Models.UserInfo
{
UserName = ex.UserName,
EducationId = lst.EducationId,
StartDate = lst.StartDate,
EndDate = lst.EndDate,
Title = lst.Title,
Major = lst.Major,
MajorDetails = lst.MajorDetails,
Info = lst.Info,
IsWorking = ex.IsWorking,
StartDate_ex=ex.StartedDate,
}).ToList();