How to build Dynamic Linq from Request.QueryString?

asp.net-mvc dynamic-linq linq

Question

I'm currently working on feature to implement/build a filter through Request.QueryString. The idea here is the filter can be on any property with in the Model For ex.,

public class Alert{
    public string Name;
    public string Status;
    public Datetime StartDate;
    public Datetime EndDate;
    public bool IsActive;
}

so the calling client wants to pass something like this in the query string startdate >=2013-10-1&Name=John&IsActive=false. I'm using System.Linq.Dynamic from Scottgu to build the where clause which takes a string but the format to build is kind of killing me. I need some pointers on the format and I'm doing the type checking through reflection before executing this and also I'm filtering this against the data that came back from DB and not passing this into the db.Any help is really appreciated!

1
0
11/17/2013 5:02:39 PM

Popular Answer

Don't reinvent the wheel if you don't need to :P

Have a look at Odata, and the .net web.api

That should do what you need.

0
10/21/2013 8:00:05 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow