I have number of tables like:
- User_cs
- UserEducation_cs
- Experience
following is the database diagram
What I need is users info
- their basic info from User_cs
- Their last education(i.e. latest degree that they acquired)
- Where they are currently working(if user is NOT working then) fields in Experience_cs will be NULL.
I so far able to do following but I am having trouble 1) how in the middle of lamda expression I do (IsWorking==true) and following that join to next table. Following is my expression
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(); Any help will be appreciated
.GroupJoin(). In that case the right side is not a single element, but an IEnumerable of all matching elements. Then you can apply further conditions or filters on that sequence to grab the desired element(s) (e.g. one, multiple or none) you need.