为什么';当Option Strict处于启用状态时,在VB.NET中将t实体转换为Linq,如Lambda?

为什么';当Option Strict处于启用状态时,在VB.NET中将t实体转换为Linq,如Lambda?,vb.net,entity-framework,Vb.net,Entity Framework,更新了新代码: 我有一些非常简单的Linq使用实体 Return NDCEntity.tbl_Ext_Mobile_PO.Where(Function(p) If(p.AssignedToUID, 0) = UserUID) 我可以在C语言中轻松地将函数(p)替换为p=>,而不会遇到麻烦。但是在VB.NET中还有一个问题。如果我尝试使用选项Strict ON执行上述操作,那么我会得到这个巨大的编译器错误 我尝试了at建议的解决方案,并将代码更改为If(p.AssignedToUID,0),但这

更新了新代码:

我有一些非常简单的Linq使用实体

Return NDCEntity.tbl_Ext_Mobile_PO.Where(Function(p) If(p.AssignedToUID, 0) = UserUID)
我可以在C语言中轻松地将
函数(p)
替换为
p=>
,而不会遇到麻烦。但是在VB.NET中还有一个问题。如果我尝试使用选项Strict ON执行上述操作,那么我会得到这个巨大的编译器错误

我尝试了at建议的解决方案,并将代码更改为If(p.AssignedToUID,0),但这给了我一个非常类似的错误

这显然是某种铸造错误。我在这个网站和其他网站上看到过很多不同的人问这个问题,但我发现没有一个人真正回答了这个问题:你必须做些什么才能让这个选项在严格的限制下工作?我更喜欢用它来工作

更新: 以下是错误文本:

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
将此内容转换为其他内容?

请参阅我的编辑

试试这个:

Return NDCEntity.tbl_Ext_Mobile_PO.Where(Function(p) If(p.AssignedToUID.HasValue, p.AssignedToUID.Value, 0) = UserUID)
Return NDCEntity.tbl_Ext_Mobile_PO.Where(Function(p) If(p.AssignedToUID, Guid.Empty) = UserUID)
我想问题可能是VB不能正确地推断出
p
总是一个
整数
,而是猜测它是可以为空的。您也可以尝试
DirectCast
Convert.ToInt32
,或
CInt
,如下所示:

Return NDCEntity.tbl_Ext_Mobile_PO.Where(Function(p) DirectCast(If(p.AssignedToUID, 0), Integer) = UserUID)
编辑:您正在将对象与Guid进行比较,因为
p
可以计算为Guid或0。将零更改为Guid,您就可以开始了。试试这个:

Return NDCEntity.tbl_Ext_Mobile_PO.Where(Function(p) If(p.AssignedToUID, Guid.Empty) = UserUID)


粘贴错误和代码的文本,屏幕截图很小,我们都很老了。可能是@asawyer的副本哦,这是一个我没有找到的问题,让我看看是不是这样。谢谢眯着眼睛看了一下,就可以看出布尔之间的实际错误转换?不允许bool,谷歌的
选项字符串不允许boolean?to boolean
作为第二次点击,它看起来和你的一模一样。@只是尝试一下并不能解决我的问题。让我更新我的问题我已经尝试过了(注意,AssignedToUID是一个Guid,而不是Int),现在我得到的是一个不同的错误。检查问题的更新