question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom type mapping

See original GitHub issue

From @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:closed
  • Created 5 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Feb 22, 2021

Create a proper, surrogate primary key?

0reactions
ErikEJcommented, Aug 19, 2022

Custom enum mapping is now available with EF Core 7 and T4 templates

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Types in Hibernate
Learn how to use custom Java classes to extend basic type mapping in Hibernate. ... Custom Types in Hibernate and the @Type Annotation....
Read more >
Custom Type Handling - Dapper .NET
To map — or better — deserialize data coming from your database into a complex custom object Dapper supports a feature named “Custom...
Read more >
Mapping a string value to a custom type in typescript
I am new to typescript and was wondering if there was a way to map a string value to a custom type when...
Read more >
Oracle User-Defined Types (UDTs) and .NET Custom Types
The custom type member mapping attributes specify the mapping between custom type members and either Oracle object attributes or Oracle collection elements.
Read more >
Custom Mapping Types - ORM
Custom Mapping Types. Doctrine allows you to create new mapping types. This can come in handy when you're missing a specific mapping type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found