PredicateBuilder、VB.net 和Where()
我正在使用 LinqKit 库中的 PredicateBuilder 类在 VB.net 中构建谓词。 我的数据源是手动构建的数据表。 我找到的所有示例都显示人们创建谓词,然后将该谓词作为参数传递给 datatable.AsEnumerable() 上的 Where()
方法。
但智能感知告诉我 Where()
方法采用“System.Func
”类型的参数,但 PredicateBuilder 返回的类型是“System.Linq” .Expressions.Expression(Of Func(Of T, Boolean))
"
我错过了什么?
例子:
Dim ds As DataTable = getData()
Dim tmp As IEnumerable(Of DataRow) = New DataTable().AsEnumerable()
' CREATE DYNAMIC LINQ WHERE CLAUSE
Dim predicate As System.Linq.Expressions.Expression(Of Func(Of DataRow, Boolean)) = PredicateBuilder.True(Of DataRow)()
If cbHPMS_ShowRequired.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_TYPE") = "REQUIRED")
End If
If cbHPMS_ShowOptional.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_TYPE") = "OPTIONAL")
End If
If cbHPMS_EmptyRecord.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_STATUS") = "EMPTY")
End If
If cbHPMS_PartialRecord.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_STATUS") = "PARTIAL")
End If
If cbHPMS_CompletedRecord.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_STATUS") = "COMPLETE")
End If
If Not String.IsNullOrEmpty(ddHPMS_RoadName.SelectedValue) And Not ddHPMS_RoadName.SelectedValue.Equals("Select") Then
predicate = predicate.And(Function(x As DataRow) x("RoadName") = ddHPMS_RoadName.SelectedValue)
End If
tmp = ds.AsEnumerable().Where(predicate)
I am building a predicate in VB.net using the PredicateBuilder class from the LinqKit library.
My datasource is a manually constructed datatable.
All the examples I've found show folks creating the predicate and then passing that predicate as an argument to the Where()
method on the datatable.AsEnumerable().
But intellisense is telling me that the Where()
method takes a paremeter of type "System.Func
", but the type returned by PredicateBuilder is "System.Linq.Expressions.Expression(Of Func(Of T, Boolean))
"
What am I missing?
Example:
Dim ds As DataTable = getData()
Dim tmp As IEnumerable(Of DataRow) = New DataTable().AsEnumerable()
' CREATE DYNAMIC LINQ WHERE CLAUSE
Dim predicate As System.Linq.Expressions.Expression(Of Func(Of DataRow, Boolean)) = PredicateBuilder.True(Of DataRow)()
If cbHPMS_ShowRequired.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_TYPE") = "REQUIRED")
End If
If cbHPMS_ShowOptional.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_TYPE") = "OPTIONAL")
End If
If cbHPMS_EmptyRecord.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_STATUS") = "EMPTY")
End If
If cbHPMS_PartialRecord.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_STATUS") = "PARTIAL")
End If
If cbHPMS_CompletedRecord.Checked Then
predicate = predicate.And(Function(x As DataRow) x("RECORD_STATUS") = "COMPLETE")
End If
If Not String.IsNullOrEmpty(ddHPMS_RoadName.SelectedValue) And Not ddHPMS_RoadName.SelectedValue.Equals("Select") Then
predicate = predicate.And(Function(x As DataRow) x("RoadName") = ddHPMS_RoadName.SelectedValue)
End If
tmp = ds.AsEnumerable().Where(predicate)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用过 LinqKit 但认为它会像
I have not used LinqKit but would think it would be like