加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 07:17:34 所属栏目:百科 来源:网络整理
导读:我正在尝试在我的 Linq to SQL查询中注入动态where子句,并且我得到一个重载异常.在查询中添加相同的表达式是否有效? qry.Where(Function(c) c.CallDate Date.Now.AddDays(-1)) 关于如何工作的任何想法? 例外情况如下: Overload resolution failed because
我正在尝试在我的 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,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,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,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:ProjectsTest ProjectsEncoreEncoreData.vb  59  9   Encore

谢谢

解决方法

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

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

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

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读