Comments (17)
Create a proper, surrogate primary key?
from efcorepowertools.
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?
from efcorepowertools.
From @mbeckenbach on February 4, 2018 7:57
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; }
}
from efcorepowertools.
OK. since I just get the generated files, maybe it would be better with
"TypeMappings": [
{ "Class:"Post", "Property":"Category", "Type": "Enums.Categories" }
]
Do a PR, perhaps?
from efcorepowertools.
From @mbeckenbach on February 6, 2018 6:54
I have never edited a vs extension. But i'll try at weekend. :-)
Thanks for the hint on the line.
from efcorepowertools.
Great, let me know if you hit any stumbling blocks! (It is a bit more involved than a standard Nuget library)
from efcorepowertools.
My Handlebars library handles this scenario now. See the project ReadMe for an example of adding an enum transformation and mapping it with a partial method.
from efcorepowertools.
@tonysneed Thanks. I assume that this will require changes to the users product code, and does not apply to EF Core Power Tools??
from efcorepowertools.
from efcorepowertools.
There are many options to do this, while preserving the modifications when reverse engineering is run a second time:
For the Enum, create at MyTypeEnum property in the partial entity class.
For special translations, use the OnModelCreating partial method to modify the model with Value Conversions https://docs.microsoft.com/en-us/ef/core/modeling/value-conversions
from efcorepowertools.
Thank you for creating this tool. I was looking for Enum mapping as well and came across this post.
I tried adding the following to efpt.renaming.json but it didn't have any effect:
"TypeMappings": [
{ "Class:"Post", "Property":"Category", "Type": "Enums.Categories" }
]
Could you please clarify what's the recommended way of mapping Enums with EF Core Power Tools? Thanks!
from efcorepowertools.
@AlexVPerl create a NonMapped enum property in a partial class
from efcorepowertools.
@ErikEJ thank you for prompt reply. Do you mean an Enum wrapper property that would set/get persisted numeric value?
If so, I was trying to avoid that since then EF will do in memory filtering when Enum is mentioned in the LINQ query.
Above, there is a mention of using OnModelCreating partial method with Value Conversions - this would be ideal. But it doesn't seem possible since all columns will be mapped in the auto generated class, and EF won't allow mapping 2 properties to single column. Having a way to ignore a column when using Rev. Eng. auto generation would make it possible to manually do Value Conversions for it. Or is there another way?
Thanks.
from efcorepowertools.
At the moment this is not supported. Happy to receive ideas or a PR for implementation.
from efcorepowertools.
@ErikEJ thank you for prompt reply. Do you mean an Enum wrapper property that would set/get persisted numeric value?
If so, I was trying to avoid that since then EF will do in memory filtering when Enum is mentioned in the LINQ query.
Above, there is a mention of using OnModelCreating partial method with Value Conversions - this would be ideal. But it doesn't seem possible since all columns will be mapped in the auto generated class, and EF won't allow mapping 2 properties to single column. Having a way to ignore a column when using Rev. Eng. auto generation would make it possible to manually do Value Conversions for it. Or is there another way?
Thanks.
@AlexVPerl , @ErikEJ - I am also looking for a way to Map an enum value to a string. If I understand correctly, the one thing blocking @AlexVPerl's suggested solution was the ability to ignore a column. Well, it seems that this feature was recently added via a pull request: #572
I'm going to give that a go, but leaving this train of thought here for others to help save them some time. I'll make another note if I have anything interesting to report
from efcorepowertools.
I'm going to give that a go, but leaving this train of thought here for others to help save them some time. I'll make another note if I have anything interesting to report
- Well, for me, good news and bad news... it looks like ignoring a column is new baked right into the UI! (Nice feature@ErikEJ)
- In my case, it seems I can not ignore the column I want to transform into an Enum because it part of the primary key... so, I will find a different approach
from efcorepowertools.
Custom enum mapping is now available with EF Core 7 and T4 templates
from efcorepowertools.
Related Issues (20)
- Run out of Memory Error HOT 3
- Command line usage documentation HOT 2
- Map Postgres stored procedures and functions HOT 18
- Eager Loading (Include) Not Working with reverse engineer, it returning related entity as empty {} HOT 1
- Crashed for create reverse engineering for PostgreSQL HOT 4
- T4 Template not found? HOT 14
- Oracle - reverse engineering - Database objects are still processing and not displayed at all HOT 1
- Duplicated configuration classes when using EntityTypeConfiguration.t4 HOT 10
- can't install on Microsoft Visual Studio Enterprise 2022 (ARM 64-bit) - Current Version 17.9.5 HOT 4
- SQL Server procedures - named parameters HOT 3
- Table Renaming is not working (or im doing wrong?) HOT 6
- #nullable -annotations not set for procedures HOT 9
- Unable to get result set shape for dbo.SP_* HOT 2
- Project table relationships are not generating correctly HOT 1
- Stored Procedures stopped working in new version HOT 5
- Is the Entity Id navigation property name convention changed? HOT 18
- Add Server Explorer launch button to localized VS versions
- Add an advanced option to add .HasColumnName() to every single property during Reverse Engineering HOT 8
- Add an option to strip a prefix from Model names during Reverse Engineering HOT 2
- Add Visualize DB Schema context menu to Server Explorer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcorepowertools.