我是Linq-to-SQL的新手,我不知道如何使用Linq中查詢的結果。我使用返回兩個表的數據的函數:從Linq-to-SQL查詢中獲取結果
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關係,我錯了嗎?
感謝
由於您要返回credito,您應該使用具體類型而不是匿名類型。 – jrummell 2012-01-12 19:21:07
如果我的查詢使用'acreditados'和'creditos'類型,我該如何使用具體類型? – 2012-01-12 19:23:12
我正在編輯我的問題說, – 2012-01-12 19:23:14