This project is read-only.
Domain Model
InsuranceSample.png

Add Criteria with Equal

LiteQuery<Policy> query = new LiteQuery<Policy>();
query.Add(x => x.Number, CriteriaOperator.Equal, 1);

Add Criteria with Like

LiteQuery<Policy> query = new LiteQuery<Policy>();
query.Add(x => x.Person.Name, CriteriaOperator.Like, "Name2");

Top

LiteQuery<Policy> query = new LiteQuery<Policy>();
query.Top(2);

Order By

LiteQuery<Policy> query = new LiteQuery<Policy>();
query.OrderBy(x => x.Number, true);

OR Operator

LiteQuery<Policy> query = new LiteQuery<Policy>();
query.Operator(QueryOperator.Or);
query.Add(x => x.Number, CriteriaOperator.Equal, 1);
query.Add(x => x.Number, CriteriaOperator.Equal, 2);

Working with Strings

The following two queries are equivalent :
LiteQuery<Policy> query = new LiteQuery<Policy>();
query.Add(x => x.PlateNo, CriteriaOperator.Equal, "PlateNo2");
query.Add(x => x.Person.Name, CriteriaOperator.Like, "Name2");
query.Add(x => x.Number, CriteriaOperator.GreaterThanEqual, 2);
query.OrderBy(x => x.Id, true);

IList<Policy> list = repository.FindBy<Policy>(query);


LiteQuery<Policy> query = new LiteQuery<Policy>();
query.Add("PlateNo", CriteriaOperator.Equal, "PlateNo2");
query.Add("Person.Name", CriteriaOperator.Like, "Name2");
query.Add("Number", CriteriaOperator.GreaterThanEqual, 2);
query.OrderBy("Id", true);

IList<Policy> list = repository.FindBy<Policy>(query);


Resources :

Wrox - Professional ASP.NET Design Patterns
http://martinfowler.com/eaaCatalog/queryObject.html
http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/
http://fabiomaulo.blogspot.com/2010/07/enhanced-query-object.html
http://psandler.wordpress.com/2009/11/10/draftdynamic-search-objects-part-1-introduction/

Last edited Jun 22, 2011 at 6:57 PM by cristi_salcescu, version 10

Comments

No comments yet.