我想在我的表中插入一個名爲'S'的列,它將根據它從表列獲得的值獲取一些字符串值。調用Linq查詢中的方法
例如:for each ID (a.z)
我想獲取它的字符串值存儲在另一個表中。該字符串值是從另一個通過Linq查詢獲取它的方法返回的。
- 是否可以從Linq調用方法?
- 我應該在同一個查詢中執行所有操作嗎?
這是信息,我需要得到結構:
a.z is the ID in the first square in table #1, from this ID I get another id in table #2, and from that I can get my string value that I need to display under column 'S'.
var q = (from a in v.A join b in v.B
on a.i equals b.j
where a.k == "aaa" && a.h == 0
select new {T = a.i, S = someMethod(a.z).ToString()})
return q;
線S = someMethod(a.z).ToString()
引起以下錯誤:
Unable to cast object of type 'System.Data.Linq.SqlClient.SqlColumn' to type 'System.Data.Linq.SqlClient.SqlMethodCall'.
您的問題還不是很清楚(我反正) - 什麼表格你指的是?這是Linq到實體還是Linq到對象?更有意義的屬性和表名也可能有幫助。 – BrokenGlass 2012-04-02 02:12:33
對不起,我是Linq的新手,Linq to Entities或Linq to Objects的含義是什麼? – user990635 2012-04-02 02:13:45
您的錯誤消息表明您使用Linq到SQL - 這就是您訪問數據庫的方式 – BrokenGlass 2012-04-02 02:15:17