Monday, August 23, 2010

Xaf Models Xaf Models and again Xaf Models

This is a sneak peek for eXpand v10.

Now it is possible to have multiple models per module as shown in the pic bellow


The question is how the use them ? I will say a few words about current approaches.

First of all your adiitional models should have Embedded Resource as Build Action


Design Time

you could use eXpand Model Editor that is based on Devexpress standalone editor. (See here more info about it here)


Now when you hit enter or double click an entry in that list the standalone editor will open up and will compine all models but will add as lastlayer the selected one thus forcing model editor to display that model as diffs (bold), and of course when you save is going to use the selected resource file as well.

Another question will be how to support child models? How for example eXpand Model Editor will now that there is a platform intepented module that also has a additional models?

To solve this one eXpand has introduced the DependentAssembly attribute. So if you apply that attribute at your win module for example like

[assembly: eXpand.Utils.DependentAssembly.DependentAssembly(typeof(PlatformIntepentedModule))]

eXpand will know that in the assembly that PlatformIntepentedModule class is defined may find more additional models to load before the selected one.

ps:models with the same name and path when loaded at runtime will be combined to one model.

With all the above we have cover the design time experince and now we have the power to involve many users messing around with our models without problems with our version control system.


To load additional model at runtime since Xaf will not do it by default we have to use the ModelDifference module and read our resources and save them as as ModelDifference objects.

eXpand provided 2 ways of doing that

Load manually using a code similar to

public class ThirdModelStore : eXpand.ExpressApp.ModelDifference.Core.ModelApplicationFromStreamStoreBase


    protected override Stream GetStream() {

        return GetType().Assembly.GetManifestResourceStream(GetType(), "ThirdModel.xafml");



for reading the resource file. And by using the code bellow you register the Store to ModelDifference store engine


public sealed partial class ExternalApplicationWindowsFormsModule : ModuleBase


    public ExternalApplicationWindowsFormsModule()




    public override void Setup(ApplicationModulesManager moduleManager)




        var modelDifferenceBaseModule = (ModelDifferenceBaseModule)moduleManager.Modules.Where(

                mbase => typeof(ModelDifferenceBaseModule).IsAssignableFrom(mbase.GetType())).SingleOrDefault();

        if (modelDifferenceBaseModule != null)

            modelDifferenceBaseModule.CreateCustomModelDifferenceStore += ModelDifferenceBaseModuleOnCreateCustomModelDifferenceStore;



    void ModelDifferenceBaseModuleOnCreateCustomModelDifferenceStore(object sender, CreateCustomModelDifferenceStoreEventArgs e) {

        e.AddExtraDiffStore(new ThirdModelStore());



or by adding an MDO_ prefix to your resource model name.


MDO stand for ModelDifferenceOjbect, RDO (Role) and UDO (User) are not supported yet.

Using the above procedures when you go to your modeldifferences listview you are going to see 2 differences object created


Now using this powerfull module the things you can do are limited by your imagination.

1.Since those 2 are Application models that mean that when using the editor to change them all changes will be propageted to all users, cause they all use the same database and models are stored there.


2.You could combine those models with others (many to many combination) (Combination of models that belong to different application is not supported though)


3.You could clone/upcast them them to another type Such as Role Or User


Subscribe to XAF feed
Subscribe to community feed

blog comments powered by Disqus