C#, Linq, Dynamic Query: Code to filter a Dynamic query outside of the Repository

Posted by Dr. Zim on Stack Overflow See other posts from Stack Overflow or by Dr. Zim
Published on 2010-03-23T06:12:41Z Indexed on 2010/03/23 6:33 UTC
Read the original article Hit count: 508

Filed under:
|
|
|

If you do something like this in your Repository:

IQueryable<CarClass> GetCars(string condition, params object[] values) {
    return db.Cars.Where(condition, values);
}

And you set the condition and values outside of the repository:

string condition = "CarMake == @Make";
object[] values = new string[] { Make = "Ford" };

var result = myRepo.GetCars( condition, values);

How would you be able to sort the result outside of the repository with Dynamic Query?

return View( "myView", result.OrderBy("Price"));

Somehow I am losing the DynamicQuery nature when the data exits from the repository. And yes, I haven't worked out how to return the CarClass type where you would normally do a Select new Carclass { fieldName = m.fieldName, ... }

© Stack Overflow or respective owner

Related posts about dynamicquery

Related posts about c#