I have a data model like this in SQL Server:
table Note
- varchar NoteText
- tinyint PriorityLevel
In my code, Entity Framework turns it into a class like:
class Note
- string NoteText
- byte PriorityLevel
Also in code I have a PriorityLevel enum which makes my code more readable:
public enum PriorityEnum : byte
{
NORMAL = 10,
IMPORTANT = 20,
URGENT = 30
}
So, I would like to use that enum directly with my Note objects, like myNote.PriorityLevel = PriorityEnum.NORMAL
rather than having to cast all the time like myNote.PriorityLevel = (byte)PriorityEnum.NORMAL
.
I already have a solution via use of Partial
class declaration, but I wind up with two similarly-named properties that map to the underlying PriorityLevel, which is messy:
class Note
- string NoteText
- byte PriorityLevel
- PriorityEnum PriorityLevelEnum (gets/sets PriorityLevel)
Naturally I would like my EF class to be defined simply like:
class Note
- string NoteText
- PriorityEnum PriorityLevel
FYI I'm using POCO generation of my EF entity classes, so I figure the solution may involve a change to the T4 templates that generate them, but I'm concerned I'm missing out on something simple. I think there may be a solution by changing field definitions in the EDMX designer but I worry that they might be overwritten next time I update the EDMX from the database definition.