XPO Simplified Criteria Syntax explained (part 1)
Re-reading my previous blog and after receiving some comments I realised I haven't really explain the essence of what I wanted to explain.
For the purpose of this Blog I will use these Classes for my Examples

What is XPO Simplified Criteria Syntax?
XPO Simplified Criteria Syntax is a neat IDE CodeRush "plugin" to XPO, although unofficially supported, DX XPO Evangelist Oliver Sturm and DevExpress do maintain the plugin and is available via Blog posts on the official DevExpress XPO Blog (http://community.devexpress.com/blogs/xpo/default.aspx). The concept of the plugin is to allow people to perform Criteria operations easier by using IntelliSense to specify what field you wish to work with, this includes nested fields. The Fields property is included in the PersistentBase which is the class from which all XPO Objects derive from whether you use (XPBaseObject, XPLiteObject, XPCustomObject or XPObject) (for a comparison of these classes please see the help file http://www.devexpress.com/help/?document=Xpo/CustomDocument3311.htm). The Fields class is usually an empty FieldsClass that does nothing, however it comes alive when the CR_XPOFieldSync is loaded into your IDE. When the Sync occurs, the plugin creates a new FieldsClass that Shadows the PersistentBase property, and populates it with all the persisted properties of your object. Lets take a quick look at an example
Normally your class would look like this
Imports DevExpress.Xpo Imports DevExpress.Data.Filtering Imports DevExpress.Xpo.Helpers Public Class TestObject Inherits XPObject Private _subject As String Public Property Subject() As String Get Return _subject End Get Set(ByVal Value As String) SetPropertyValue("Subject", _subject, Value) End Set End Property Private _status As TestObjectStatus Public Property Status() As TestObjectStatus Get Return _status End Get Set(ByVal Value As TestObjectStatus) SetPropertyValue("Status", _status, Value) End Set End Property End Class
This will still have the PersistentBase Fields property exposed however it will be empty and useless, however run your XPOFieldSync and it will generate a Shadow FieldsClass and Fields property for your Object and generate code for each of your properties
#Region "XPO nested fields class - don't edit manually" Public Shadows Class FieldsClass Inherits DevExpress.Xpo.XPObject.FieldsClass Public Sub New() MyBase.New() End Sub Public Sub New(ByVal propertyName As String) MyBase.New(propertyName) End Sub Public ReadOnly Property Subject() As OperandProperty Get Return New OperandProperty(GetNestedName("Subject")) End Get End Property Public ReadOnly Property Status() As TestObjectStatus.FieldsClass Get Return New TestObjectStatus.FieldsClass(GetNestedName("Status")) End Get End Property End Class Private Shared _fields As FieldsClass Public Shared Shadows ReadOnly Property Fields() As FieldsClass Get If ReferenceEquals(_fields, Nothing) Then _fields = New FieldsClass() End If Return _fields End Get End Property #End Region
Usually when performing Criteria such as obtaining a Collection of all Objects that contain "ThisSubject" in the Subject field you would normally write this code
Dim MyXPObjects As New XPCollection(Of TestObject)(New BinaryOperator("Subject", "ThisSubject"))
Now with the XPO Simplified Criteria Syntax you can change this line to
Dim MyXPObjects As New XPCollection(Of TestObject)(New BinaryOperator(TestObject.Fields.Subject, New OperandValue("ThisSubject"), BinaryOperatorType.Equal))
Why should I useĀ XPO Simplified Criteria Syntax?
Well, I have found that the "Simplified Criteria Syntax" doesn't really explain the full potential of this little plugin.
- You can define your Criteria using IntelliSense
- Allows you to have strongly typed references to your fields, this means that should you change the Title field to Name (for some reason) you will receive a Compile error whereever you have used your TestObject.Fields.Title which wouldn't exist before as it would now be TestObject.Fields.Name
No 2 above is the main reason I use the XPO plugin, I use the Fields property for everything in my app such as Fieldname property on GridColumns, Property for DataBinding and also use it within my XPO objects.
I will explain use scenarios a bit later.
How do I start using XPO Simplified Criteria Syntax?
- Close Visual Studio
- Download the plugin from the Blog
http://community.devexpress.com/blogs/xpo/default.aspx - Extract the CR_XPOFieldSync.dll into your {My Documents}\DevExpress\IDE Tools\Community\PlugIns folder
- Start Visual Studio
- Go to the menu DevExpress > Options
(or I believe CTRL+ALT+SHIFT+O if you are using VS Express and don't have the DevExpress menu)
- On the Left hand Tree List go to IDE > Shortcuts
- I would suggest creating your own folder to store your own shortcuts, it makes it easier to find them in future, so click on the New Folder window
Then name it what you like, however set the folder to Root
- Now ensure your folder is selected and click on the New Shortcut button
- Setup the options
Pick a key combination that you will find easy, I personally use CTRL+1
Make sure it is Enabled
Select the SyncXPOClass command
Then set the use to Editor > Code > In XPO Persistent Class - THEN MAKE SURE YOU CLICK OK
You should now be able to go into your Persisted Class and Press your shortcut (in the example CTRL+1) and you should see the FieldsClass generated at the bottom.
As this post is going to be bigger than ben hur, I am going to break it up so at least information is starting to get out. In the next post I will go through some Use Case Scenario's and why I strongly believe this plugin is actually a big feature of XPO and not just a "Helper" plugin.
Till then
Background: eXpress Persistent Objects (XPO) is a Object Relation Mapping (ORM) solution provided by DevExpress (DX), XPO is a Object->Database model (ie. You create strongly typed objects to which XPO will handle the persistance to a database store). XPO supports persisting to 16databases out of the box (although you can easily extend their DataStore classes to gain support for your database). See here for more details http://www.devexpress.com/Help/?document=XPO

Should AussieALF stay bald?
Latest Comments
- How to make XPO only...
Hi Sean, Very true ;) however keep in mi... More...
09-Apr-10 - How to make XPO only...
True, but it's worth noting that DX do ... More...
09-Apr-10 - How to make XPO only...
I would have to check with Gary, as alth... More...
09-Apr-10 - How to make XPO only...
Hi, I agree it seems like a "normal" thi... More...
09-Apr-10 - How to make XPO only...
Another question, how does it work with ... More...
09-Apr-10





