Wednesday, February 3, 2010

Multiple datastores support


WorldCreator creates dynamic types for used within Xaf. It is doing that by compiling code templates at WorldCreator module setup method. To find those templates it has to query a persistent datastore using XPO. Now when you create a new XPO session it will check if all object types that XPObjectType table contains if are valid. So if you have used customizedtypesinfo to create runtime associations since it is called after module setup it will throw an exception complaining for invalid tables.

Saying the above you understand that there is no way to open a connection to an XPO database that has records for objects with associations that have not fully defined.


[AttributeUsage(AttributeTargets.Assembly,AllowMultiple = true)]

public class DataStoreAttribute:Attribute


    readonly Type _nameSpaceType;

    readonly string _dataStoreNameSuffix;


    public DataStoreAttribute(Type nameSpaceType, string dataStoreNameSuffix) {

        _nameSpaceType = nameSpaceType;

        _dataStoreNameSuffix = dataStoreNameSuffix;



    public string NameSpace {

        get { return _nameSpaceType.Namespace; }



    public string DataStoreNameSuffix {

        get { return _dataStoreNameSuffix; }



You can add the above attribute to your AssemblyInfo.cs file to decouple all classes inside a namespace. I have already decouple WorldCreator objects using the following line in eXpand.BaseImpl

[assembly: DataStore(typeof(PersistentAssemblyInfo),"WorldCreator")]

The first parameter is the type that will provide the namespace to decouple and the secode the datastore name suffix.

If DataStoreAttribute is applied it will create a database in the same server as your default connectionstring. But if you want you can provide your own custom connectionstring like


    <add name="ConnectionString" connectionString="Integrated Security=SSPI;Pooling=false;Data Source=SERVER;Initial Catalog=Solution1;"/>

    <add name="WorldCreatorConnectionString" connectionString="Integrated Security=SSPI;Pooling=false;Data Source=OTHERSERVER;Initial Catalog=WorldCreator;"/>


Ps: Sharing objects is not supported , so you have to be sure that all classes are defined in the namespace that you are decoupling

Subscribe to XAF feed
Subscribe to community feed

blog comments powered by Disqus