【发布时间】:2012-01-12 19:17:35
【问题描述】:
我是 Linq-to-SQL 的新手,我不知道在 Linq 中使用查询结果的正确方法是什么。我使用了一个返回两个表数据的函数:
public IQueryable RegresaDatosCredito(int idC)
{
var credito = from a in context.acreditados
where a.creditos.IDCredito == idC
select new
{
Monto = a.Cantidad,
Tasa = a.creditos.TasaInteres,
Plazo = a.creditos.Plazo,
Periodo = a.creditos.Periodo,
Producto = a.creditos.Producto,
Expediente = a.creditos.Expediente
};
return credito;
}
此查询将始终从我的数据库中返回一行。然后我想使用这个查询的结果并在不同的文本框中显示它。在其他类中,我创建了一个方法来打印这个结果,就像我上面提到的那样。
private void SomeMethod()
{
try
{
var credito = operaciones.RegresaDatosCredito(idCred);
text_MontoC.Text = credito.Monto;
text_TasaC.Text = credito.Tasa;
text_PlazoC.Text = credito.Plazo;
text_PeriodoC.Text = credito.Periodo;
text_ProductoC.Text = credito.Producto;
text_ExpedienteC.Text = credito.Expediente;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
但是我无法访问像credito.???这样的结果,正确的方法是什么?
在RegresaDatosCredito 我返回一个IQueryable 数据类型,因为在查询中我使用 fk 关系连接两个表,我错了吗?
谢谢
【问题讨论】:
-
由于您要返还贷方,因此您应该使用具体类型而不是匿名类型。
-
如果我的查询使用 'acreditados' 和 'creditos' 类型,我该如何使用具体类型?
-
我正在编辑我的问题以说明这一点
标签: c# linq-to-sql