New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom type mapping #621
Comments
Anything goes, and the tool is open source and welcomes contributions! Could you show an example of what a class with a Enum would look like before and after this? |
Hi @ErikEJ, good to hear that. A typical example for my use case would be like this. You have a custom enum in some folder/namespace and a generated class like the ones below. namespace EFCoreTest.Enums
{
public enum Categories
{
SomeCategory = 0,
AnotherCategory = 1,
MoreCategories = 2
}
} namespace EFCoreTest.Models
{
public partial class Post
{
public int Id { get; set; }
public string Text { get; set; }
public int Category { get; set; }
}
} After transformation the class would simply look like this: public partial class Post
{
public int Id { get; set; }
public string Text { get; set; }
public Enums.Categories Category { get; set; }
} |
OK. since I just get the generated files, maybe it would be better with
Do a PR, perhaps? |
I have never edited a vs extension. But i'll try at weekend. :-) |
Great, let me know if you hit any stumbling blocks! (It is a bit more involved than a standard Nuget library) |
This issue was moved to ErikEJ/EFCorePowerTools#16 |
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?
The text was updated successfully, but these errors were encountered: