Quantcast
Channel: eXpandFramework RSS
Viewing all articles
Browse latest Browse all 861

BLOG by Robert Anderson: Fluent queries with DevExpress XPO - Intro

$
0
0

There are many ways to perform queries with XPO.

You can do this:

1
Session.FindObject<Contact>(newBinaryOperator("Name","Elvis"));

or this

1
Session.FindObject<Contact>(CriteriaOperator.Parse("Name = 'Elvis'"));

Another way to use the simplified criteria syntax, and with the Xpo_EasyFields CodeRush plugin. Then you can do:

1
Session.FindObject<Contact>(Customer.Fields.Name=="Elvis");

For each of the above, you can optionally query within the transaction by passing in the PersistentCriteriaEvaluationBehavior.InTransaction parameter.

Or we can use LINQ via XPQuery<T>.TransformExpression().

123
Session.FindObject<Contact>(XPQuery<Contact>.TransformExpression(Session,c=>c.Name=="Elvis"));

All of these methods are powerful, but the power comes at a cost. The syntax is neither elegant nor particularly clear and as a result it is not very practical to maintain or test.

A Fluent Interface for XPO

How about if we could do the following?

1234
varcustomer=Session.Query().Contacts.ByName("Elvis");

Or, for a more elaborate example:

123456789101112
varcustomer=Session.Query().InTransaction.Contacts.ByPosition("Developer").ThatHave.NoPhoto().And.TasksInProgress().And.TasksWith(Priority.High).FirstOrDefault();

In the next post I’ll show how to put the fluent interface code together.


Viewing all articles
Browse latest Browse all 861

Trending Articles