Custom type mapping
See original GitHub issueFrom @mbeckenbach on February 3, 2018 9:40
This project is awesome! It feels just like the db first workflow is coming back. But there is one feature that I am really missing.
In EF6 DB First, there is this amazing feature of mapping external types to properties. This can be perfectly be used for transforming an integer culumn into a C# enum.
EF Core supports enum properties and maps those to integer columns in the database.
When doing a reverse engineer, all integer columns get generated as integer properties as it should be. Then one can simply change a properties type to some enum type, which exists in the project. Works great.
But when repeating the reverse engineer process to update the generated model from database, the file will be overwritten, which removes the modification of the properties type.
So I was thinking about how it would be possible to preserve this modification.
One way of doing this could be to create a code template for a specific class file. I had a look at EntityFrameworkCore.Scaffolding.Handlebars by @tonysneed but I dont see a way for doing this.
Another idea was to extend the efpt.config.json with an array of type mappings, that could be applied after code generation. Could something like that be implemented in your tool?
{
"ContextClassName": "EfcoretestContext",
"DatabaseType": 2,
"IdReplace": false,
"IncludeConnectionString": true,
"OutputPath": "Models",
"ProjectRootNamespace": "EFCoreTest",
"SelectedToBeGenerated": 0,
"Tables": [ "dbo.Posts", "dbo.Users" ],
"UseDatabaseNames": false,
"UseFluentApiOnly": true,
"UseHandleBars": true,
"UseInflector": true,
"TypeMappings": [
{ "Column": "dbo.Posts.Category", "Type": "Enums.Categories" }
]
}
Copied from original issue: ErikEJ/SqlCeToolbox#621
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (13 by maintainers)
Top GitHub Comments
Create a proper, surrogate primary key?
Custom enum mapping is now available with EF Core 7 and T4 templates