Linq - Relationship with 3 tables

Asked

Viewed 875 times

0

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

Tabcolecao 1 - N Tabvolume and Tabvolume 1 - N Tobacconist

Example:

inserir a descrição da imagem aqui

I need to present the View as follows:

inserir a descrição da imagem aqui

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

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

I really appreciate any help.

Carlos

  • Two important questions: 1. You navigation properties in models? 2. Have you heard of Begincollectionitem?

  • No. I haven’t heard of Begincollectionitem. I’ll look it up. Thank you.

  • Apostille K19 - "K32 - Web Development with ASP.NET MVC" responds well to what you need, very fast to read and hold! Click here to download!

  • Thank you for the indication.

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
                     }
                     );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.