When modeling you can use any type name for attribute types. This name is what we call a “Common name”.
When ECO is given the model and tries to turn it into a runtime model, AND when when we derive code from the model – the common name should however resolve to some available .net type.
You do this mapping in the EcoDataTypes.xml file that you find in the <installdir>/Config/ folder for ECO and in in the bin folder for AppComplete.
<Type CanonicalName=”ClassLibrary1.CrazyType” Type=”ClassLibrary1.CrazyType, ClassLibrary1, Version=22.214.171.124, Culture=neutral, PublicKeyToken=5348474bcfb2dae2″>
<CommonName Name=”CrazyType” CaseSensitive=”false”/>
<CommonName Name=”ClassLibrary1.CrazyType” CaseSensitive=”false”/>
<LanguageName Language=”C#” Name=”ClassLibrary1.CrazyType”/>
<LanguageName Language=”Delhpi” Name=”ClassLibrary1.CrazyType”/>
<LanguageName Language=”Oxygene” Name=”ClassLibrary1.CrazyType”/>
<LanguageName Language=”VB” Name=”ClassLibrary1.CrazyType”/>
ECO/AppComplete needs to be able to load this from the Type description provided – this means that you should have the classLibrary in the GAC – (especially for ECO since there is no telling where VisualStudio reads its non GACed assemblies from).
IF ECO CANNOT FIND A DEFINITION IN EcoDataTypes.xml for a common name – ECO WILL TREAT IT AS STRING – so no error or anything – just a string type.
Any given “real”-.net type can then have one or more PersistenceMappers. The persistenceMapper is the definition on how a .net type is handled by the database (inserts, updates, deletes, selects). You can create your own using ECO. You do this by implementing the IGenericSingleColumnAttributemapping interface.
Once you have your PersistenceMapper done you install it by calling PersistenceMapperXXX.SqlDatabaseConfig.SetPMapper(“CommonName”,typeof(YourPMapper)). It is of course important to do this before you start the EcoSpace or it will be to late.
ECO will resolve not only from “CommonName” but also from Class.Attribute, or .net type. This means that you can replace how System.int is handled by installing PersistenceMapperXXX.SqlDatabaseConfig.SetPMapper(“System.Int”,typeof(YourPMapper)) – or by using the designer as shown in this image:
Tying it together
The attribute in the model has a property “PersistenceMapper”:
(if you do not see it, go to Package and set ORMappingConfigMode to Medium or All)
The common, preferred and suggested way to work is to leave the PersistenceMapper at “<Default>” .
When “<Default>” is used – we first translate your common name to a .net type, then look up the PersistenceMapper for that type.
For attributes with special needs you can replace the “<Default>” with whatever name you used in SetPMapper – we will then use that Pmapper even if there is another Pmapper acting as the default choice for the .net type you get on the attribute.
You can also tell ECO/AppComplete what PMapper should be used for a common name, and even set other properties in the runtime model (not visible in design time) by stating in the EcoDataTypes.xml file what values those tagged values should have:
<Type CanonicalName=”Text” Type=”System.String”>
<CommonName Name=”text” CaseSensitive=”false”/>
<CommonName Name=”memo” CaseSensitive=”false”/>
<LanguageName Language=”C#” Name=”string”/>
<LanguageName Language=”Delphi” Name=”string”/>
<LanguageName Language=”Oxygene” Name=”string”/>
<LanguageName Language=”VB” Name=”String”/>
<TaggedValue Tag=”Eco.PMapper” Value=”StringAsText“/>
<TaggedValue Tag=”Eco.Length” Value=”-1″/>
And this way you can leave the PersistenceMapper property at “<Default>” since the “<Default>” will be replaced by “StringAsText” for your attributes that has the common name type of “Text”.