PredicateBuilder, VB.net and Where()
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.Selecte开发者_JAVA技巧dValue)
End If
tmp = ds.AsEnumerable().Where(predicate)
I have not used LinqKit but would think it would be like
tmp = ds.AsEnumerable().Where(predicate.Compile())
精彩评论