简体   繁体   English

PredicateBuilder、VB.net 和 Where()

[英]PredicateBuilder, VB.net and Where()

I am building a predicate in VB.net using the PredicateBuilder class from the LinqKit library.我正在使用 LinqKit 库中的 PredicateBuilder class 在 VB.net 中构建谓词。 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().我发现的所有示例都显示人们创建谓词,然后将该谓词作为参数传递给 datatable.AsEnumerable() 上的Where()方法。

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)) "但是智能感知告诉我Where()方法采用“ System.Func ”类型的参数,但 PredicateBuilder 返回的类型是“ 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)

I have not used LinqKit but would think it would be like我没有使用过 LinqKit,但会认为它会像

tmp = ds.AsEnumerable().Where(predicate.Compile())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM