Wednesday, 2 April 2014

Add multiple where condition dynamically in Linq to Entity framework


How to use LinqKit for Linq to Entity framework

Use LinqKit predicateBuilder class in our code.

Add LinqKit dll in your application reference and add library in your page like :

using LinqKit;

Write the following code to achieve your requirement for multiple dynamic where condition

var predicate = LinqKit.PredicateBuilder.True<tblInfo>();
predicate = predicate.And(p => p.Name == "Ajay");
predicate = predicate.And(p => p.City == 2);
var Res = objDB.tblInfoes.AsExpandable().Where(predicate);


AsExpandable() is must required for Linq to Entity framework



Download Linqkit from Here. You can read more about LinqKit from this blog

No comments:

Post a comment