可以在單個查詢中混合使用Linq to SQL和存儲過程調用嗎?使用存儲過程混合實體框架Linq
var query = from asset in this.Context.Assets
let status = this.Context.GetAssetAttributeLastStatusHistory(asset.idAsset)
select new { asset, status };
就像這樣,其中GetAssetAttributeLastStatusHistory
是映射到存儲過程的函數導入。
我想在SQL而不是在內存中。在內存中,我可以爲每個資產設置一個。
我需要執行分頁和篩選,並且如果查詢在SQL Server中執行,它會更好地執行。編號: 此代碼生成一個異常。 Yes I did. I get an exception. LINQ to Entities does not recognize the method 'System.Data.Objects.ObjectResult.. GetAssetAttributeLastStatusHistory(System.Nullable1[System.Guid])' method, and this method cannot be translated into a store expression.
從我知道這是因爲框架無法將該表達式轉換爲SQL表達式。
EDIT2:
看來這是不可能的。在RAW SQL和LINQ中都是不可能的。 感謝您的輸入。
你試過了嗎?如果是的話,你會得到什麼錯誤/不好的結果? –
是的,我做到了。我得到一個異常。 'LINQ to Entities does not recognized the method'System.Data.Objects.ObjectResult .. GetAssetAttributeLastStatusHistory(System.Nullable'1 [System.Guid])''method,this method can not be transolve into a store expression.' –
Add that例外(和堆棧跟蹤)請你的問題。 –