Multiple Join in LINQ

public List<UserInfo> gettopUserInfo()

{

    List<UserInfo> userInfos = new List<UserInfo>();

    var result = (from u in _dbPIPESS.Users

                  join p in _dbPIPESS.Professions on u.ProfessionID equals p.ID into p_join

                  from p in p_join.DefaultIfEmpty()

                  join sp in _dbPIPESS.Specialities on u.SpecialtyID equals sp.ID into sp_join

                  from sp in sp_join.DefaultIfEmpty()

                  join inter in _dbPIPESS.Interests on u.InterestsID equals inter.ID into inter_join

                  from inter in inter_join.DefaultIfEmpty()

                  join cont in _dbPIPESS.Countrys on u.CountryID equals cont.ID into cont_join

                  from cont in cont_join.DefaultIfEmpty()

                  join stat in _dbPIPESS.States on u.StateId equals stat.Id into stat_join

                  from stat in stat_join.DefaultIfEmpty()

                  join prac in _dbPIPESS.Practices on u.PracticeTypeID equals prac.ID into prac_join

                  from prac in prac_join.DefaultIfEmpty()

                  select new UserInfo

                  {

                       ID = u.ID,

                       ProfessionType = p.ProfessionType,

                       SpecialityType = sp.SpecialityType,

                       InterestsType = inter.InterestsType,

                       FirstName = u.FirstName,

                       MiddleInitial = u.MiddleInitial,

                       LastName = u.LastName,

                       Suffix = u.Suffix,

                       Email = u.Email,

                       Phone = u.Phone,

                       Fax = u.Fax,

                       Department = u.Department,

                       Address1 = u.Address1,

                       Address2 = u.Address2,

                       City = u.City,

                       CountryName = cont.CountryName,

                       Name = stat.Name,

                       StateName = u.StateName,

                       ZipCode = u.ZipCode,

                       PracticeType = prac.PracticeType,

                       Years = u.Years,

                       UserName = u.UserName,

                       Password = u.Password

                   });

 

    if (result.Count() > 0)

        userInfos = result.ToList();

    return userInfos;

}

Ebook Download
View all
Learn
View all