0

我在动态 LINQ 文件 (dynamic.cs) 的帮助下使用以下方法构建动态查询:

    Dim qs As New List(Of KeyValuePair(Of String, Object))

    qs.Add(New KeyValuePair(Of String, Object)("Price >= @", 10))
    qs.Add(New KeyValuePair(Of String, Object)("Price <= @", 50))
    qs.Add(New KeyValuePair(Of String, Object)("GoLive=  @", False))
    qs.Add(New KeyValuePair(Of String, Object)("Format = @", "DVD"))
    qs.Add(New KeyValuePair(Of String, Object)("Format = @", "BLR"))

    Dim products = From p In data.Products
                   Select p

    For Each q In qs
        products = products.Where(q.Key, q.Value)
    Next
    Dim results = products.ToList

这可以满足您的期望,但看看我是如何在“格式”字段中同时查找“DVD”和“BLR”的?这会查询两个选项,而不是任何一个。

有没有办法使用上述查询构建方法以某种方式查询任一选项,或者最好像这样组合“格式”字段:

    qs.Add(New KeyValuePair(Of String, Object)("Format = @ OR Format = ", both options here))
4

0 回答 0