如何使用LINQ
转换下面的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
};
答案 0 :(得分: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 您不需要将整个查询转换为方法语法。您只能转换过滤where
部分。