There are many ways to perform queries with XPO.
You can do this:
| |
or this
| |
Another way to use the simplified criteria syntax, and with the Xpo_EasyFields CodeRush plugin. Then you can do:
| |
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().
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?
| |
Or, for a more elaborate example:
| |
In the next post I’ll show how to put the fluent interface code together.