Using Linq to Create Filter Strings RRS feed

  • Question

  • I am working on upgrading an application I developed about 5-6 years ago to .Net 3.5 - the application uses filter strings extensively.  For example, it creates a DataView on a DataSet and then applies a filter string to the RowFilter property of the view to filter the data shown in the view.  I created a class called "Filter" that makes it easy to create and manipulate these filter strings.  The class has the capability to create a basic filter from a field name, an operand, and a criteria value - example: "RecordID = 1" and it also has the capability to create more complex filter strings using Logical operators (AND, OR, etc) to combine basic filter strings.  The output of the filter class is a string that can be applied to a DataView to filter the results.

    I'm wondering if there is a way to do this using Linq.  I think the primary way of doing it with Linq is to create a Linq query against the dataset and use the results of that to create the view.  I would prefer not to do it that way for several reasons...primarily I have a lot of code written around the current way of doing it and I'm only looking to replace the filter class I created with a better way to create filter strings, but also I would like to have a very dynamic way of creating these filter strings at runtime and applying them to the RowFilter property of the DataView to change the data displayed.

    Any suggestions on how I can do this with Linq?



    Wednesday, October 28, 2009 5:42 PM