【发布时间】:2011-10-17 20:37:01
【问题描述】:
我对 MVC 和实体框架还很陌生,但我相信这应该是直截了当的。我有一个带有布尔“活动”标志的类。然后我有一个按日期降序返回结果的函数。我要做的就是确保只返回活动记录。应该很简单,但它失败并出现以下错误:
错误 13 重载解析失败,因为无法使用以下参数调用可访问的“Where”: 'System.Linq.Enumerable'中定义的扩展方法'Public Function Where(predicate As System.Func(Of Review, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of Review)':'Boolean'类型的值无法转换为“System.Func(Of PowellCasting.Models.Review, Integer, Boolean)”。 'System.Linq.Enumerable' 中定义的扩展方法'Public Function Where(predicate As System.Func(Of Review, Boolean)) As System.Collections.Generic.IEnumerable(Of Review)':'Boolean' 类型的值不能转换为“System.Func(Of PowellCasting.Models.Review, Boolean)”。 'System.Linq.Queryable 中定义的扩展方法'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of Review, Integer, Boolean))) As System.Linq.IQueryable(Of Review)' ':'Boolean' 类型的值不能转换为 'System.Linq.Expressions.Expression(Of System.Func(Of PowellCasting.Models.Review, Integer, Boolean))'。 'System.Linq.Queryable'中定义的扩展方法'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of Review, Boolean))) As System.Linq.IQueryable(Of Review)': 'Boolean' 类型的值无法转换为 'System.Linq.Expressions.Expression(Of System.Func(Of PowellCasting.Models.Review, Boolean))'。 C:\Web Projects\Powell Casting\PowellCasting\PowellCasting\Models\Review.vb 42 14 PowellCasting
看起来它不喜欢比较布尔值,但它们具有相同的数据类型。我相信这应该很简单,但希望能得到一些帮助。请在下面查看我的代码。
公开课回顾
Private PowellCastingDB As PowellCastingEntites = New PowellCastingEntites
<ScaffoldColumn(False)>
Public Property ReviewID As Integer
<Required(ErrorMessage:="An review title is required")>
<StringLength(256)>
<DisplayName("Title")>
Public Property Title As String
<DisplayName("Heading")>
Public Property Heading As String
<DisplayName("ReviewText")>
<StringLength(4096)>
Public Property ReviewText As String
<DisplayName("Author")>
<StringLength(256)>
Public Property Author As String
<DisplayName("Publication")>
<StringLength(150)>
Public Property Publication As String
<DisplayName("PublicationDate")>
Public Property PublicationDate As Date
<DisplayName("PublicationLink")>
<StringLength(1000)>
Public Property PublicationLink As String
<DisplayName("Image")>
<StringLength(512)>
Public Property Image As String
<DisplayName("Active")>
Public Property Active As Boolean
Public Property Reviews As List(Of Review)
Public Function GetLatestReviews(ByVal count As Integer) As List(Of Review)
Return PowellCastingDB.Reviews.Where(Active = True).
OrderByDescending(Function(a) a.PublicationDate).
Take(count).
ToList()
End Function
结束类 结束命名空间
【问题讨论】:
-
我是用 C# 编写的,所以我不提供这个作为答案,但你不需要像 .Where(Function(review) review.Active = True) 这样的东西吗?
标签: asp.net sql vb.net linq entity-framework