更新了新代码:
我有一些使用实体的非常简单的 Linq
Return NDCEntity.tbl_Ext_Mobile_PO.Where(Function(p) If(p.AssignedToUID, 0) = UserUID)
我可以在 C# 中做到这一点,只需简单地替换Function(p)
为p =>
. 但是在 VB.NET 中还有一个额外的问题。如果我尝试在 Option Strict ON 的情况下执行上述操作,那么我会收到这个巨大的编译器错误。
我尝试了在Entity Framework Where 方法参数中建议的解决方案,并将我的代码更改为有,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
这个做点什么吗?