Simple use:
string propertyName = "Name";
object value = "Value";
EqExpression<Customer> filter = new EqExpression<Customer>(propertyName, value);
Criteria<Customer> criteria = new Criteria<Customer>(filter);
var q = criteria.AsQueryable(dbContext.Customers);
foreach(var cus in q)
{
...
}
Lambda:
LambdaExpression<Customer> filter = new LambdaExpression<Customer>(c => c.Name == "...");
Criteria<Customer> criteria = new Criteria<Customer>(filter);
var q = criteria.AsQueryable(dbContext.Customers);
foreach(var cus in q)
{
...
}
Build Dynamic Queries
string propertyName = "Name";
object value = "Value";
EqExpression<Customer> filter = new EqExpression<Customer>(propertyName, value);
filter = filter.And(c => c.Country == "US").And(c => c.City == "badon");
Criteria<Customer> criteria = new Criteria<Customer>(filter);
var q = criteria.AsQueryable(dbContext.Customers);
foreach(var cus in q)
{
...
}
Page:
Criteria<Customer> criteria = new Criteria<Customer>(filter);
criteria.FirstResult = pageNumber * pageSize;
criteria.MaxResults = pageSize;
var q = criteria.AsQueryable(dbContext.Customers);
foreach(var cus in q)
{
...
}
Order by
Criteria<Customer> criteria = new Criteria<Customer>(filter);
criteria.AddOrder("Name", ListSortDirection.Ascending);
criteria.AddOrder(c => c.City, ListSortDirection.Ascending);
var q = criteria.AsQueryable(dbContext.Customers);
foreach(var cus in q)
{
...
}
Serialize
string value = "Value";
LambdaExpression<Customer, string> e = new LambdaExpression<Customer, string>((x, a0) => x.Name == a0, value);
using(MemoryStream ms = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, e);
ms.Position = 0;
var result = (LambdaExpression<Customer>)bf.Deserialize(ms);
}