No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
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 | [[File:2019-06-18 16h00 03.png|none|thumb|473x473px]]In Code, you can do this: | ||
if (rbPMappMDrivenServer.Checked) | if (rbPMappMDrivenServer.Checked) | ||
Line 18: | Line 18: | ||
persistenceMapperSqlServer1.NewMappingProvider = _ORMappingForMDrivenServer; | persistenceMapperSqlServer1.NewMappingProvider = _ORMappingForMDrivenServer; | ||
} | } | ||
To on-a-per-class-level set your keys (commonly needed when reversing) | 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]] | [[File:2019-06-18 17h49 00.png|none|thumb|466x466px]] | ||
You can name the PrimaryKey anything unique - make sure | 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 | 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 | The one we use by default is the DefaultEcoIdMapper. 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 database | 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 | 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 08:43, 9 February 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:
In Code, you can 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:
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:
The one we use by default is the DefaultEcoIdMapper. 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.