Setting up the EDMX Model to Generate DevExpress XPO/XAF Objects

So you have started using DevExpress XPO/XAF and now you would like to see how to use the EDMX (Entity Data Model XML) visual designer within Visual Studio to draw your entities and relationships.  First let’s explain the steps we are going to do and what is taking place, then I’ll give you the steps to accomplish this.

The EDMX design surface is what is currently being used to generate Entity Framework code.  What we have done is to intercept the saving of the diagram and use this to generate XPO/XAF code according to DevExpress syntax.  Why?  So that we can more quickly visualize and see our entity model.  My goal was to create a tool that I could sit down with my end users in a planning session and crank out a prototype.  If anyone has users you know that they know what they don’t want as soon as they see it.  Let’s cut that cycle down so that we can more get better software out faster.

Step 1.  Download and install the EDMX Visual Studio Extension for XAF/XPO.

The extension can be found  Just download it and install the Liekhus.EntityFramework.XAFExtensions.vsix file.  This is the Visual Studio Extension file.  You can then ensure that it is installed by looking at your installed extensions by going to Tools –> Extension Manager.  You should see something like this below screen shot.


The code generator is now installed.  Let’s move to the next step.

Step 2.  Create your XAF project (if necessary)

If you are creating a new project then use the standard XAF Solution project to create a new project.   There are no special tips or tricks here. 

If you are using an existing project then you are set and ready to go.

Step 3.  Add an EDMX (Entity Data Model) to your Module project

Add a “New Item” to your Module project.  Select ADO.NET Entity Data Model under the Data section as shown below.


The name of the file does not matter.  Once you start creating your model, the name of the entities will drive the name of the code generated files.  Select the Empty Model option from the next screen.


Click the Finish button and the designer surface will be created.

Step 4.  Turn off the Entity Framework default code generation.

This is the most important step.  You must turn off the default action of the EDMX file.  Right click on the designer surface and view the Properties.  Set the Code Generation Strategy to None.  This is what causes the model to create the Entity Framework classes.  By installing the Visual Studio Extension in the above steps, when the model is saved you will now generate XPO/XAF classes based on DevExpress standards.


Step 5.  Create your model.

You can either use the toolbox, drag tables from the data explorer or use the wizards to create your model.  This step is using the standard EDMX designer to model the entities and their relationships.  There is no trickery here.  Below is an example model that I have built using the tool.


One thing to note is that we have built several of the XPO/XAF properties into the designer.  The properties below are visible when you click on an Entity.


You can see these properties when clicking on a property.


As you can see, you can set most of the properties just by entering simple property values.  In the above example, simply by putting in the display message in the Rule Required Message the XAF toolset will require the field to be completed and will also throw the above message when needed.

You will also notice all key fields have been removed from the model.  This is because all entities will be generated from the base object DevExpress.Persistent.BaseImpl.BaseObject.  This provides the Oid key based upon the XPO design.  You can change the base object, this is strictly a default and the recommended approach.

Step 6.  Save your model.

Simply save your model.  You should see several things take place here. 

For each of your entities, a concrete and generated source file will be created as partial classes.  For example, the Album class above will look like this below


The concrete class is where you should put your custom code (if needed) for things such as OnSave or BeforeSave logic.  This will depend on your implementation and/or solution for your needs.  By default it should look something like this.  This file will only be created the first time.  Once it is saved, your code will not be altered from this point forward.


The generated class is following the Windows form designer pattern by including the code generated file directly below the concrete class. DO NOT (I repeat DO NOT) make changes to this code in the designer class.  Each time you save your EDMX file, this file will be overwritten. 


What you will see here is that the attributes to support XPO/XAF are generated based upon the properties that were set on the model.  Try exploring with different settings and see how they react in the application.

Step 7.  Build your application according to XAF standards and best practices. 

Set any additional properties and attributes on the XAF Model.  You can run your application and see your entities in action.

That’s it for this tutorial.  What we have done is to use the designer surface of the ADO.NET Entity Data Model and intercept the save to code generate XPO/XAF classes.  Once that is done DevExpress has done a tremendous job on their framework and we let them take over from there. 

If you have any questions/comments/concerns, please feel free to post them below.  And remember, stay tuned as there are more tools and tricks to come.

Print | posted on Friday, November 4, 2011 9:51 PM


# re: Setting up the EDMX Model to Generate DevExpress XPO/XAF Objects

left by Preetham Reddy at 11/11/2011 12:59 PM Gravatar

I have an application that was developed using EF Code First.. I would like to create XAF application to manage backend.. XAF is really good at that..

Since the model is already created using POCO's and the database is generated, I guess I can use the designer to generate EDMX file and then generate XPO classes but I don't want to use BaseObject since the primary keys already exist.

What do I do? If I change it manually in the partial class, I guess it will be overridden next time.

# re: Setting up the EDMX Model to Generate DevExpress XPO/XAF Objects

left by shower panel at 11/21/2011 4:20 AM Gravatar
Good writing is used to recommend it. Highly recommended!

# re: Setting up the EDMX Model to Generate DevExpress XPO/XAF Objects

left by Holger at 12/19/2011 10:50 AM Gravatar
Hi Patric,

great stuff! I have tried it with VS2010 and XAF 11.2. It worked very well.
Now I wonder, what the best way would be, to change an existing XAF project to the EDMX.

As I read the previous comment of Reddy, it seems to be the same issue.

Any suggestions?


# re: Setting up the EDMX Model to Generate DevExpress XPO/XAF Objects

left by Mario Blataric at 1/7/2012 4:41 AM Gravatar

I have two problems:
1. All entities are generated in root of the project and I'm following new XAF project layout that puts all business objects to sub-folder. That makes me move all the entities to a subfolder which becomes problematic when custom code already exists. Is there a way to define where new files should be created?

2. Model gives me error if I don't define key property on entity (and this tutorial does the same). Project can be compiled, but constantly seeing bunch of errors isn't nice. Also, I can't set BaseObject type for the entity - do I need to include something?

Post A Comment