multiple joins in LINQ Query with 3 tables on the same column

I am trying to create a linq query with 3 tables involved. The main table (A) has 2 fields that are pointing to the same table (C) from which I need to return Full Name (FirstName + LastName) for each of the two fields. In addition I need to return a third Full Name (FirstName + LastName) from table (C) using a middle table (B) that has a common field with A (taxID), how can I create a linq query that does that at once please? Any help is appreciated. I am using Entity Framework

        public List<PCMHSiteVisitsScheduleDTO> GetAllTEST(int selectedTaxID, bool completedVisits)
    {
        List<PCMHSiteVisitsScheduleDTO> ObjSiteVisitsList = new List<PCMHSiteVisitsScheduleDTO>();
        try
        {
            var SVQ = from schedules in ObjContext.PCMHSiteVisitsSchedules.AsQueryable()
                      join managers1 in ObjContext.NetworkManagers.AsQueryable() on schedules.ScheduledBy equals managers1.ManagerID
                      join managers2 in ObjContext.NetworkManagers.AsQueryable() on schedules.CompletedBy equals managers2.ManagerID
                      join crosswalk in ObjContext.ProviderManagerCrosswalks.AsQueryable() on schedules.TaxID equals crosswalk.TaxID
                      join managers3 in ObjContext.NetworkManagers.AsQueryable() on crosswalk.ManagerID equals managers3.ManagerID
                      select new
                      {
                          schedules.SiteVisitID,
                          schedules.TaxID,
                          schedules.ScheduledBy,
                          schedules.CompletedBy                              
                      };

            foreach (var item in SVQ)
            {
                ObjSiteVisitsList.Add(new PCMHSiteVisitsScheduleDTO
                {
                    SiteVisitID = item.SiteVisitID,
                    TaxID = item.TaxID,
                    ScheduledBy = item.ScheduledBy,
                    CompletedBy = item.CompletedBy,
                });
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return ObjSiteVisitsList;
    }

I am attaching an image to explain

thanks in advanceImage with the three tables below.



from Recent Questions - Stack Overflow https://ift.tt/3AEmBbp
https://ift.tt/3CKCspD

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)