我有出現語法正確以下select語句:如何使用LINQ/Linq2E返回具體類型的新對象?
var accounts = from i in db.IRSBASEFLs
join vr in db.VSARules on i.VSACode equals vr.VSACode into rules
from rule in rules.DefaultIfEmpty()
select new ImporterAccount(i, rule, RuleType.Liquidity);
然而,這將引發:我已經嘗試添加一個「建設者」類返回一個新的ImporterAccount
Only parameterless constructors and initializers are supported in LINQ to Entities.
,但這太失敗了,這次使用:
LINQ to Entities does not recognize the method 'IrsalDAL.ImporterAccount CreateImporterAccount(IrsalDAL.IRSBASEFL, IrsalDAL.VSARule, IrsalUtilities.RuleType)' method, and this method cannot be translated into a store expression.
我需要進行計算,最好是在構造函數中,所以我以一個有點困惑如何實現這一目標?
爲什麼當類不是我的實體模型的一部分時,會拋出一個L2E異常?
如何返回一個新對象並對其進行計算?
謝謝,但是我得到「已經有一個打開的DataReader與此命令關聯,必須先關閉」? – BlueChippy
這似乎是一個單獨的問題。我編輯了我的答案,並提供了一個可能的解決方案的鏈接。 –
收到你的答案,雖然我實際上首先將所有內容都返回到anonymouse類型,然後從中選擇以解決第二個問題(這是延遲加載和多個結果集) – BlueChippy