與新代碼更新時間:當Option Strict爲ON時,爲什麼VB.NET中的Entities-to-Linq不像Lambda?
我有一些非常簡單的LINQ中使用實體
Return NDCEntity.tbl_Ext_Mobile_PO.Where(Function(p) If(p.AssignedToUID, 0) = UserUID)
我能做到這一點在C#中無故障的簡單與p =>
更換Function(p)
。但在VB.NET中還有一個額外的問題。如果我嘗試使用Option Strict ON進行上述操作,那麼我會得到這個大量的編譯器錯誤。
我試着在Entity Framework Where method parameters上建議的解決方案,並將我的代碼更改爲If(p.AssignedToUID, 0)
,但這給我一個非常類似的錯誤。
這顯然是某種鑄造錯誤。我已經看到有人在這個網站和其他網站上詢問這個問題的幾個變種,但是我發現的其中一個實際上並沒有答案:你需要做什麼才能使Option Strict ON工作?我更喜歡和它一起工作。
更新: 這裏的錯誤文本:
Error 1 Overload resolution failed because no accessible 'Where' can be called with these arguments:
'Public Function Where(predicate As String, ParamArray parameters() As System.Data.Objects.ObjectParameter) As System.Data.Objects.ObjectQuery(Of tbl_Ext_Mobile_PO)': Lambda expression cannot be converted to 'String' because 'String' is not a delegate type.
Extension method 'Public Function Where(predicate As System.Func(Of tbl_Ext_Mobile_PO, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of tbl_Ext_Mobile_PO)' defined in 'System.Linq.Enumerable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of tbl_Ext_Mobile_PO, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Func(Of tbl_Ext_Mobile_PO, Boolean)) As System.Collections.Generic.IEnumerable(Of tbl_Ext_Mobile_PO)' defined in 'System.Linq.Enumerable': Cannot infer a common type, and Option Strict On does not allow 'Object' to be assumed.
Extension method 'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of tbl_Ext_Mobile_PO, Integer, Boolean))) As System.Linq.IQueryable(Of tbl_Ext_Mobile_PO)' defined in 'System.Linq.Queryable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of tbl_Ext_Mobile_PO, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of tbl_Ext_Mobile_PO, Boolean))) As System.Linq.IQueryable(Of tbl_Ext_Mobile_PO)' defined in 'System.Linq.Queryable': Cannot infer a common type, and Option Strict On does not allow 'Object' to be assumed. C:\Programming\Sources\NDC\Custom Web Services\Mobile SAP WebServices\1.0.0.0\MobileSAPWebServices\MobileSAPWebServices\SAPMobileWS.asmx.vb 29 20 MobileSAPWebServices
我應該DirectCast
荷蘭國際集團這東西嗎?
粘貼,屏幕截圖是微小的,我們都老了。 – asawyer
可能重複的[實體框架凡方法參數](http://stackoverflow.com/questions/5633334/entity-framework-where-method-parameters) – asawyer
@asawyer哦,這是我沒有找到的問題,讓我看看是否是這樣。謝謝! – cost