Query 3 tables using LINQ and return a Json object

Asked

Viewed 68 times

0

How do I query the database between 3 tables using LINQ by returning a JSON object following the Structure below ?

Public class PedidoGrupo{

    int id ;
    string nome ;
    public virtual List<Pedido> pedidos ;

}

    Public class Pedido{

    int id ;
    int id_PedidoGrupo;
    string destino;
    public virtual List<Pedido> ItensPedidos ;

}

    Public class PedidoItem{

    int id ;
    int id_Pedido;
    string produto;
    string marca;
    string modelo;


}


{  "id": 1,
"Nome": "Rafael",
"pedidos": [{"id":1
            "Destino":"SaoPaulo"
            "ItensPedidos": [{"Produto":"celular",
                             "marca":"Apple",
                             "modelo":"Iphone7"
            }
         ]
    }

that is, I compare the similar id’s and I want to return an array of objects within Pedidositems that is within orders, which in turn is within Pedidosgroup.

What’s the right way to do it? I’m having a hard time.

  • How is the context of your application? Is it using Codefirst? Dbfirst?

  • Model Code First

  • Have you tried using includes in LINQ? https://msdn.microsoft.com/en-us/library/bb738708(v=vs.110). aspx

No answers

Browser other questions tagged

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