Doing your own Primary keys
No edit summary
No edit summary
Line 1: Line 1:
MDriven legacy is to give the name Eco_Id to primary keys. New MDrivenSystems use <Classname>Id to make the database easier to read.
MDriven legacy is to give the name Eco_Id to primary keys. New MDrivenSystems use <code><Classname>Id</code> to make the database easier to read.


You can choose the default strategy freely if you are using MDriven Framework in Visual Studio.
You can choose the default strategy freely if you are using MDriven Framework in Visual Studio.


In the Play-button-prototyper, you can choose from legacy or MDriven:
In the Play-button-prototyper, you can choose from legacy or MDriven:
[[File:2019-06-18 16h00 03.png|none|thumb|473x473px]]In Code, you can do this:
[[File:2019-06-18 16h00 03.png|none|thumb|473x473px]]In Code, do this:


       if (rbPMappMDrivenServer.Checked)
       if (rbPMappMDrivenServer.Checked)
Line 24: Line 24:
You must also choose the PrimaryKeyMapper and this is one of the named KeyMappers that are in the PersistenceMappers SqlDatabaseConfig. If you have not created your own, you can use any of the ones we provide:
You must also choose the PrimaryKeyMapper and this is one of the named KeyMappers that are in the PersistenceMappers SqlDatabaseConfig. If you have not created your own, you can use any of the ones we provide:
[[File:2019-06-18 17h54 18.png|none|thumb|977x977px]]
[[File:2019-06-18 17h54 18.png|none|thumb|977x977px]]
The one we use by default is the DefaultEcoIdMapper. This creates an integer id from a common cursor kept in the Eco_id table.
We use DefaultEcoIdMapper by default. This creates an integer id from a common cursor kept in the Eco_id table.


If you use a mapper that is Auto assigned id from the database, you must state SaveAction = DBAssigned - this way we know to reread it upon insert.
If you use a mapper that is Auto assigned id from the database, you must state SaveAction = DBAssigned - this way, we know to reread it upon insert.


If you use another mapper with no auto-assign, you must choose SaveAction=Freeze - so that the key may remain unchanged after the first insert.
If you use another mapper with no auto-assign, you must choose SaveAction=Freeze so that the key may remain unchanged after the first insert.
[[File:2019-06-18 17h59 30.png|none|thumb|776x776px|x]]
[[File:2019-06-18 17h59 30.png|none|thumb|776x776px|x]]
[[Category:MDriven Framework]]
[[Category:MDriven Framework]]
[[Category:Database]]
[[Category:Database]]
[[Category:Advanced]]
[[Category:Advanced]]

Revision as of 07:26, 20 June 2023

MDriven legacy is to give the name Eco_Id to primary keys. New MDrivenSystems use <Classname>Id to make the database easier to read.

You can choose the default strategy freely if you are using MDriven Framework in Visual Studio.

In the Play-button-prototyper, you can choose from legacy or MDriven:

2019-06-18 16h00 03.png

In Code, do this:

     if (rbPMappMDrivenServer.Checked)
     {
       if (_ORMappingForMDrivenServer == null)
       {
         _ORMappingForMDrivenServer = new Eco.Persistence.ORMapping.DefaultORMappingBuilder();
         _ORMappingForMDrivenServer.ChildMapRootClass = true;
         _ORMappingForMDrivenServer.DefaultSingleLinkColumnName = "<Name>ID";
         _ORMappingForMDrivenServer.IdColumnName = "<TableName>ID";
       }
       persistenceMapperSqlServer1.RunTimeMappingProvider = _ORMappingForMDrivenServer;
       persistenceMapperSqlServer1.NewMappingProvider = _ORMappingForMDrivenServer;
     }

To on-a-per-class-level, set your keys (commonly needed when reversing). You must go to package and choose OrMappingMode=All. After this, you will see the following per selected class:

2019-06-18 17h49 00.png

You can name the PrimaryKey anything unique - make sure you have a corresponding attribute defined in the class.

You must also choose the PrimaryKeyMapper and this is one of the named KeyMappers that are in the PersistenceMappers SqlDatabaseConfig. If you have not created your own, you can use any of the ones we provide:

2019-06-18 17h54 18.png

We use DefaultEcoIdMapper by default. This creates an integer id from a common cursor kept in the Eco_id table.

If you use a mapper that is Auto assigned id from the database, you must state SaveAction = DBAssigned - this way, we know to reread it upon insert.

If you use another mapper with no auto-assign, you must choose SaveAction=Freeze so that the key may remain unchanged after the first insert.

x
This page was edited 115 days ago on 01/11/2024. What links here