Linq - Linked Tables on Common identifier

Lets say you have Table A and Table B and a Table which has a sole function of joining the two - not so uncommon.  You want all the records from Table A and corresponding records from Table B but you don't want to include your join table.

Using Entity Framework you could do something like this. The highlighted row is what I want to draw your attention to.  See that instead of a true join I have selected the collection of TableB records in Table A    A.TableB



public IQueryable<Network> getjoinedData(int Id)
        {
            var myRequest = (from A in db.TableA
                             from B in A.TableB
                             join C in db.TableC on B.programId equals c.programId

                             where A.active == true
                             && B.active == true
                             && C.active == true
                             select n);
   
            return myRequest;
}


Comments

Popular posts from this blog

Linq Exclude from separate list

Sorting Ascending and Descending

Linq Query Syntax vs Method Syntax