Linq - Relationship with 3 tables

0

Good morning. In my project (C # MVC), I need to query with three tables, being:

TabCollection 1 - N TabVolume and TabVolume 1 - N TabAuthor

Example:

IneedtodisplaytheViewasfollows:

The first difficulty is to create this query, where a collection can have n volumes, and each volume can have n authors. I'm using Entity Framework and Linq.

The second difficulty is the presentation in the View. How to work with this data in View and / or Partial Views.

Thank you very much for any help.

Carlos

    
asked by anonymous 28.06.2016 / 17:46

1 answer

1
var q = (from c in   Datacontext.Tbcolecao
        join b in Datacontext.Tbvolume on c.ColecaoId equals b.ColecaoId
        join d in Datacontext.tbautor on b.volumeId equals d.volumeId
        where c.ColecaoId == b.ColecaoId && b.volumeId == d.volumeId
                     select new
                     {
                         nomeColecao=c.descricaocolecao
                         .
                         .
                         .
                         nomeVolume = b.descricaoVolume
                         .
                         NomeAutor = d.Nome
                     }
                     );
    
26.08.2016 / 11:02