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
 };
asked Dec 11, 2012 at 13:47
2
  • Why would you want to? It's going to end up being much harder to read, after two joins. Commented Dec 11, 2012 at 13:50
  • This is because I need to do a Dynamic LINQ like in Scot Gu's blog weblogs.asp.net/scottgu/archive/2008/01/07/… Commented Dec 11, 2012 at 13:54

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.

answered Dec 11, 2012 at 14:01
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.