Doing your own Primary keys
No edit summary
m ((username removed) (log details removed))
 
(7 intermediate revisions by 3 users not shown)
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 go like this:
[[File:2019-06-18 16h00 03.png|none|thumb|473x473px]]In Code, do this:


      else if (rbPMappMDrivenServer.Checked)
      if (rbPMappMDrivenServer.Checked)
       {
       {
         if (_ORMappingForMDrivenServer == null)
         if (_ORMappingForMDrivenServer == null)
Line 18: Line 18:
         persistenceMapperSqlServer1.NewMappingProvider = _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:
[[File:2019-06-18 17h49 00.png|none|thumb|466x466px]]
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:
[[File:2019-06-18 17h54 18.png|none|thumb|977x977px]]
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.
[[File:2019-06-18 17h59 30.png|none|thumb|776x776px|x]]
[[Category:MDriven Framework]]
[[Category:Database]]
[[Category:Advanced]]

Latest revision as of 06:05, 11 January 2024

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 121 days ago on 01/11/2024. What links here