views:

666

answers:

1

Hi. Ok, I asked this question before, but deleted it as the way I went about describing my problem was wrong.

Firstly, let me state that Im creating a .NET3.5 Winforms app using C# and Plinqo (Professional Linq to Objects) as my ORM. Here's my situation: I have a DataGridview that is populated from a SortableBindingList<T> - in my case, formed from a List<Task> which is simply represented as follows:

public class Task {
    public long TaskID { get; set; }
    public string TaskDescription { get; set; }
    public enumPriority TaskPriority { get; set; }
    public DateTime DueDate { get; set; }
    public double PercentageComplete { get; set; }
}


Now, I want to provide a Dialog to my user to allow him/her to Filter this list. I envision passing in a list of property names and associated DataType into the Dialog that I can use to populate a ComboBox. So the user will choose which property they want to query from the comboBox and based on the selection the appropriate comparers and UI control will be made available for the user to enter in thier criteria. Lastly, it will contain an AND/OR togglebutton at the end which the user can use to add additional criterion. Each criterion will be an object of type FilterItem as shown below:

public class FilterItem {
    public string MappedPropertyName { get; set; }
    public enumComparer Comparer { get; set; }
    public object FilterValue { get; set; }
    public enumOpertor Operator { get; set; }
}


After the user constructs his/her query, I intend to pass this as a List<FilterItem> back to my calling form, which can then iterate thru the list and allow me to filter the original List<Task>.

This is all fine, and something that I can put together with ease. But I want to make sure that the ACTUAL filter mechanism I go with is as strongly-typed as possible, and not using bulit up strings like in the Dynamic Query Library. (I used to do something similar previously with ADO.NET, DataViews and dynamically constructing a RowFilter string)

I've read up on Joseph Albahari's PredicatBuilder and an article on tomasp.net, but I seem heavily confused with it and expression trees in general.

I sincerely seek your assistance in helping me better understand these concepts, and how to go about using it up so that my intended architecture can work with it.

Much appreciation!

A: 

Additionally, I know I can do something like:

private SortableBindingList<Task> GetSortedTaskList()
{
        List<Task> list = new List<Task>();
        var query = DataUtil.GetUserTasks(xSys.Current.UserID);
        if (/*description condition met*/)
        {
            query = query.Where(x => x.TaskDescription.Contains(FilterDesc));
        }
        if (/*due date condition met*/)
        {
            query = query.Where(x => x.DueDate >= FilterDate);
        }
        if (/*priority condition met*/)
        {
            query = query.Where(x => x.TaskPriority == FilterPriority);
        }

    ...

        list = query.ToList();
        return new SortableBindingList<ArcTask>(list);
}


but this does not seem very scalable and 'dynamic'.

Shalan
nevermind...I'll stick with this for now
Shalan