Type mapping, OR-Mapping
No edit summary
No edit summary
Line 1: Line 1:
When modeling you can use any type name for attribute types. This name is what we call a “Common name”.
When modeling, you can use any type name for attribute types. This name is what we call a “Common name”.


[[File:Mapping - 1.png|frameless]]
[[File:Mapping - 1.png|frameless]]


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.
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 resolve to some available .net type, however.


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.
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=1.0.0.0, Culture=neutral, PublicKeyToken=5348474bcfb2dae2">
<Type CanonicalName="ClassLibrary1.CrazyType" Type="ClassLibrary1.CrazyType, ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5348474bcfb2dae2">
Line 23: Line 23:
</Type>
</Type>


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).
ECO/AppComplete needs 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.
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 ==
== OR-Mapping ==
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.
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 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.
Once you have your PersistenceMapper done, you 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 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:
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:


[[File:Mapping - 2.png|frameless|540x540px]]
[[File:Mapping - 2.png|frameless|540x540px]]


=== Tying it together ===
=== Tying It Together ===
[[File:Mapping - 1.png|frameless]]
[[File:Mapping - 1.png|frameless]]


Line 43: Line 43:
[[File:Mapping - 3.png|frameless|244x244px]]
[[File:Mapping - 3.png|frameless|244x244px]]


(if you do not see it, go to Package and set ORMappingConfigMode to Medium or All)
(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>” .
The common, preferred and suggested way to work is to leave the PersistenceMapper at “<Default>” .
Line 49: Line 49:
When “<Default>” is used – we first translate your common name to a .net type, then look up the PersistenceMapper for that type.
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.
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:
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:
Line 73: Line 73:
</Type>
</Type>


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”.
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”.
[[Category:ORMapping]]
[[Category:ORMapping]]

Revision as of 06:12, 17 March 2023

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 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 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 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.

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, you 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 91 days ago on 02/10/2024. What links here