How do you convert this Sql to Entity framework?

Asked

Viewed 61 times

1

I’m having difficulty passing this sql to the Entity Framework I’m using mvc 4.

select pc.Nome, pc.Endereco, pc.Bairro, pc.Numero, 
    pc.Telefone, pc.Email, ma.descricao
    from PontoDeColeta pc
    Inner join Material ma on(pc.IDMaterial = ma.IDMaterial)
    inner join Material on (ma.Descricao like '%variavel%')

1 answer

0

You didn’t give much detail of the model, but your query in Brasili would look like this.

var PontoDeColeta_Material = (from t1 in Context.PontoDeColeta
                              join t3 in Context.Material on t1.IDMaterial equals t3.IDMaterial
                              where SqlMethods.Like(t3.Descricao, "%" + "variavel" + "%")
                              select new
                              {
                                  t1.Nome,
                                  t1.Endereco,
                                  t1.Bairro,
                                  t1.Numero,
                                  t1.Telefone,
                                  t1.Email,
                                  t3.descricao,
                              }).Tolist();

I see no reason for you to make 2 Join with the same table and not used the data of the two, I think a Where in place of the last Join would be what you needed.

Browser other questions tagged

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