[英]I dont know what im doing wrong with my lambda expression, can someone correct me?
I'm using FrameworkEntity and have two classes:我正在使用 FrameworkEntity 并有两个类:
public class InfoComplementarEmpresaModel
{
public int idempresa { get; set; }
[Key]
public string idcomplemento { get; set; }
public string idinformacao { get; set; }
public string conteudocomplemento { get; set; }
public string periodocomplemento { get; set; }
}
and和
public class InfoComplementarModel
{
public int idlayout { get; set; }
[Key]
public int idinformacao { get; set; }
public string codigoinformacao { get; set; }
public string descricaoinformacao { get; set; }
public int tipoinformacao { get; set; }
}
The lambda join im trying to do is the following:我试图做的 lambda 连接如下:
public List<string> GetTipoENomeDeInformacaoComplementarEmpresa(string idDaEmpresa)
{
List<string> listaDeTipos = new List<string>();
int idDaEmpresaNoFormatocerto = Convert.ToInt32(idDaEmpresa);
listaDeTipos.Add("Criar novo preenchimento de valores");
var nomesDeInformacoes = db.InformacoesComplementaresDaEmpresa
.Where(a => a.idempresa == idDaEmpresaNoFormatocerto)
.Join(db.InformacoesComplementaresDoLayout,
infocompempresa => new {infocompempresa.idinformacao},
infocomplayout => new {infocomplayout.idinformacao},
(ice, icl) => ice.idinformacao)
.ToList();
// some method that will put nomesDeInformacoes in listaDeTipos
return listaDeTipos;
}
The Join accuses "The type arguments for method Queryable.Join(IQueryable, IQueryable, Expression>, Expression>, Expression>) cannot be inferred from the usage. Try specifying the type arguments explicitly" Join 指责“无法从用法推断出方法 Queryable.Join(IQueryable, IQueryable, Expression>, Expression>, Expression>) 的类型参数。尝试明确指定类型参数”
I FIGURED IT OUT我想到了
there were various problems:出现了各种问题:
idinformacao in InfoComplementarEmpresaModel was a string instead of a int InfoComplementarEmpresaModel 中的 idinformacao 是一个字符串而不是一个 int
Then i discovered that ALL the anonymous names in the join must remain the same, resulting in:然后我发现连接中的所有匿名名称必须保持不变,导致:
var nomesDeInformacoes = db.InformacoesComplementaresDaEmpresa.Where(a => a.idempresa == idDaEmpresaNoFormatocerto)
.Join(db.InformacoesComplementaresDoLayout,
ice => ice.idinformacao ,
icl => icl.idinformacao ,
(ice, icl) => new { ice, icl } )
.Select(
//creating a class to accept the fields i want
})
.ToList();
This guy works, returning in the class im creating.这家伙工作,返回我创建的班级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.