0

How can I convert the LINQ query below using LAMBDA Expressions ?

    var select = from si in db.San_Imovel
                 join sic in db.San_Imovel_caracteristica
                 on si.Imovel_Id equals Convert.ToInt64(sic.Imovel_Id)
                 join sf in db.San_Filial
                 on si.Credenciada_Id equals sf.Credenciada_Id
                 where si.Credenciada_Id == credenciada_Id
                 && (si.GrupoImovel_Id.ToString().Contains("1") || si.GrupoImovel_Id.ToString().Contains("2"))
                 && (si.Status_Id.ToString().Contains("1") || si.Status_Id.ToString().Contains("12"))
                 && si.NomeArquivo != null
                 && (si.Imovel_Id.ToString().Contains(""))
                 select new
                 {
                     si.Celula_Id,
                     si.Credenciada_Id,
                     si.Imovel_Id,
                     si.NomeArquivo,
                     si.TipoDsc1,
                     si.BairroDsc1,
                     si.AreaRealPrivativa,
                     sic.VagasGaragem,
                     si.ValorImovel,
                     si.ValorCondominio,
                     si.ValorIPTU,
                     si.Lat2,
                     si.Lon2,
                     sf.ApelidoCredenciada,
                     sf.ddd,
                     sf.TelefoneVenda,
                     sf.TelefoneLocacao,
                     sf.Email,
                     si.Bairro1,
                     si.NomeCidade,
                     si.Transacao_ID
                 };
2

1 Answer 1

1
var query = 
   db.San_Imovel
     .Join(db.San_Imovel_caracteristica,
           si => Imovel_Id,
           sic => Convert.ToInt64(sic.Imovel_Id),
           (si, sic) => new { si, sic })
     .Join(db.San_Filial,
           x => x.si.Credenciada_Id,
           sf => sf.Credenciada_Id,
           (x, sf) => new { x.si, x.sic, sf })
     .Where(x => x.si.Credenciada_Id == credenciada_Id &&
                 (x.si.GrupoImovel_Id.ToString().Contains("1") || 
                  x.si.GrupoImovel_Id.ToString().Contains("2")) &&
                 (x.si.Status_Id.ToString().Contains("1") || 
                  x.si.Status_Id.ToString().Contains("12")) &&
                  x.si.NomeArquivo != null &&
                 (x.si.Imovel_Id.ToString().Contains(""))
     .Select(x => new {
                     x.si.Celula_Id,
                     x.si.Credenciada_Id,
                     x.si.Imovel_Id,
                     x.si.NomeArquivo,
                     x.si.TipoDsc1,
                     x.si.BairroDsc1,
                     x.si.AreaRealPrivativa,
                     x.sic.VagasGaragem,
                     x.si.ValorImovel,
                     x.si.ValorCondominio,
                     x.si.ValorIPTU,
                     x.si.Lat2,
                     x.si.Lon2,
                     x.sf.ApelidoCredenciada,
                     x.sf.ddd,
                     x.sf.TelefoneVenda,
                     x.sf.TelefoneLocacao,
                     x.sf.Email,
                     x.si.Bairro1,
                     x.si.NomeCidade,
                     x.si.Transacao_ID
                 });

BTW you don't need to convert whole query to method syntax. You can convert only filtering where part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.