当前位置 : 主页 > 编程语言 > c语言 >

vb.net – 动态中的日期比较Linq中的子句给出了重载异常

来源:互联网 收集:自由互联 发布时间:2021-06-24
我正在尝试在我的 Linq to SQL查询中注入动态where子句,并且我得到一个重载异常.在查询中添加相同的表达式是否有效? qry.Where(Function(c) c.CallDate Date.Now.AddDays(-1)) 关于如何工作的任何想法
我正在尝试在我的 Linq to SQL查询中注入动态where子句,并且我得到一个重载异常.在查询中添加相同的表达式是否有效?

qry.Where(Function(c) c.CallDate < Date.Now.AddDays(-1))

关于如何工作的任何想法?

例外情况如下:

Overload resolution failed because no accessible 'Where' can be called with these arguments:
Extension method 'Public Function Where(predicate As System.Func(Of Calls, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of Calls)' defined in 'System.Linq.Enumerable': Nested function does not have the same signature as delegate 'System.Func(Of Calls, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Func(Of Calls, Boolean)) As System.Collections.Generic.IEnumerable(Of Calls)' defined in 'System.Linq.Enumerable': Option Strict On disallows implicit conversions from 'Boolean?' to 'Boolean'.
Extension method 'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of Calls, Integer, Boolean))) As System.Linq.IQueryable(Of Calls)' defined in 'System.Linq.Queryable': Nested function does not have the same signature as delegate 'System.Func(Of Calls, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of Calls, Boolean))) As System.Linq.IQueryable(Of Calls)' defined in 'System.Linq.Queryable': Option Strict On disallows implicit conversions from 'Boolean?' to 'Boolean'.  C:\Projects\Test Projects\Encore\EncoreData.vb  59  9   Encore

谢谢

刚刚在这里捅了一下,之前没见过,但是你走了.

看起来关键部分是这两行你的异常:

Nested function does not have the same
signature as delegate ‘System.Func(Of
Calls, Integer, Boolean)’.

disallows implicit conversions from
‘Boolean?’ to ‘Boolean’.

所以你创建的函数似乎有一个boolean类型的输出? ,而where子句期望一个布尔值.并且系统不能从布尔值进行隐式转换?因为可能存在空值而导致布尔值.

因此,您可以尝试使用显式转换编写函数. (布尔)或Convert.ToBool.

网友评论