How to convert this Sql to entity framework?

1

I'm having trouble passing this sql to 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%')
    
asked by anonymous 05.06.2016 / 02:38

1 answer

0

You did not give much detail of the model, but your linq query 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 do not see any reason why you are doing 2 join with the same table and not used the data of the two, I think that a Where in the place of the last join would be what you needed.

    
01.11.2016 / 19:54