Context:
I use Database-first approach to generate my entities with Entity Framework Core and with use of Scaffolding. Each time I change something in the database I run Scaffolding with -f
parameter to rewrite generated entities. So far so good. In my database schema I have a few Lookup tables that serve the purpose as Enums for my other tables and those other tables has Foreign key on them.
Problem:
I would like to generate from these lookup tables Enums which I can use in my code. These enums should be populated by the data in the lookup table (Id, Value). Is something like this even possible ?
I saw that one can ignore those tables from Entity generation and link their own enums with use of value-conversions. But is this really the only way around ?
Example of my database schema:
TABLE: Category
Id | Value |
---|---|
0 | Cardio |
1 | Strength |
2 | Hyperthrophy |
TABLE: Exercise
Id | Name | Category |
---|---|---|
0 | Deadlift | 1 |
1 | Benchpress | 1 |
2 | Jogging | 0 |
So from table Category
I would like to generate simple Enum:
public enum Category {
Cardio = 0,
Strength = 1,
Hyperthrophy = 2
}
and then I want it to be used in the entity Exercise
like:
public partial class Exercise {
public Exercise() {
}
public int Id { get; set; }
public string Name { get; set; }
public Category Category { get; set; }
}