这是我的功能:
Public Function ListPublishedArticles(ByVal startingDate As DateTime) As List(Of Article)
Dim db As ArticleEntities = ArticleEntitiesFactory.Current()
Dim listArticles As List(Of Article) = Nothing
If startingDate <> Nothing Then
listArticles = db.Articles.Where(Function(x) x.Publish = True And x.startTime <= startingDate)
End If
Return listArticles
End Function
在.Where()上,我收到以下错误:
No Accessible 'where' can be called without narrowing conversion. Candidates are
Public Function Where(Of Article)(IEnumerable(Of Article), Func(Of Article, Boolean)) As IEnumerable(Of Article) (In Class Enumerable)
Public Function Where(Of Article)(IQueryable(Of Article), Expression(Of Func(Article, Boolean))) As IQueryable(Of Article) (In Class Queryable)
我理解错误但不确定如何修复它,我怎么告诉它我正在使用哪一个?在msdn上它表示忽略此错误,将Option Strict设置为Off,但它已经关闭。它没有在底部的错误列表中显示为错误,只是一个红色下划线,但它阻止我继续使用.OrderBy()和更多函数。
感谢。
答案 0 :(得分:2)
我意识到这篇文章很老了,但我最近遇到了同样的问题,原因是我正在评估一个布尔值? =真。我通过在我的布尔值上调用.Equals()扩展方法避免了转换整个表达式?参数即。
.Where(Function(x) x.Publish.Equals(True) And x.startTime <= startingDate)
或者
.Where(Function(x) (x.Publish.HasValue AndAlso x.Publish.Value = True) And x.startTime <= startingDate)
答案 1 :(得分:0)
尝试拨打ToList()
。这将获得List(Of Article)
答案 2 :(得分:0)
好吧,似乎答案显而易见,我只是没有得到,我需要做的就是CType Where表达式中的任何一种类型的参数如下:
.Where(Ctype(Function(x) x.Publish = True And x.startTime <= startingDate, Func(Of Article, Boolean)))