我有这样的表的数目:LINQ表达式具有多个与条件联接在每个加入
- User_cs
- UserEducation_cs
- 经验
我需要的是用户信息
- 他们从User_cs获取的基本信息
- 他们上一次接受的教育(即:他们获得的最新学历)
- Experience_cs中他们当前正在工作的位置(如果用户不在工作的话)将为NULL。
我到目前为止能够做到以下,但我遇到了麻烦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();
任何帮助将不胜感激
您的当前表达式的错误是什么? – slawekwin
它只是在做现在的连接,但我想要的是有条件,我需要检查1)IsWorking in Experience_cs,应该是true 2)在Education_cs中,只有最后一个行应该包含在连接中 – Alex
我认为你必须使用'.GroupJoin()'。在这种情况下,右侧不是单个元素,而是所有匹配元素的IEnumerable。然后,您可以对该序列应用更多条件或过滤器,以获取所需的所需元素(例如,一个,多个或无)。 – Oliver