Type mapping, OR-Mapping

When modeling, you can use any type name for attribute types. This name is what we call a “Common name”.

Mapping - 1.png

When ECO is given the model and tries to turn it into a runtime model, AND when we derive code from the model – the common name should resolve to some available .net type, however.

Do this mapping in the EcoDataTypes.xml file that you find in the <installdir>/Config/ folder for ECO and in the bin folder for AppComplete.

<Type CanonicalName="ClassLibrary1.CrazyType" Type="ClassLibrary1.CrazyType, ClassLibrary1, Version=1.0.0.0, 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"/>

</Type>

ECO/AppComplete needs to load this from the Type description provided – this means 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.

OR-Mapping

Any given “real”-.net type can then have one or more PersistenceMappers. The PersistenceMapper is the definition of 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, install it by calling PersistenceMapperXXX.SqlDatabaseConfig.SetPMapper(“CommonName”,typeof(YourPMapper)). It is important to do this before you start the EcoSpace or it will be too late.

ECO will resolve not only from “CommonName” but also from Class.Attribute, or .net type. This means 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:

Mapping - 2.png

Tying It Together

Mapping - 1.png

The attribute in the model has a property “PersistenceMapper”:

Mapping - 3.png

(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"/>

</Type>

This way, you can leave the PersistenceMapper property at “<Default>” since the “<Default>” will be replaced by “StringAsText” for your attributes that have the common name type of “Text”.

This page was edited more than 6 months ago on 06/17/2024. What links here