Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6653479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:16:28+00:00 2026-05-26T01:16:28+00:00

I have a data model like this in SQL Server: table Note – varchar

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:16:28+00:00Added an answer on May 26, 2026 at 1:16 am

    With current version of entity framework you will always need both properties because EF is not able to convert enums automatically and use them in mapping (that will change in future version).

    So your entity defined in EDMX must have byte property and your partial class must expose second property using the enum and make conversion to byte internally within getter and setter. What you can do is reduce accessibility of your former mapped property. The disadvantage of this scenario is that Linq-to-entities queries cannot use your enum property – they must use original byte property and code defining the queries must have access to that property.

    Modifying template to create enum properties for you would not be so easy because the template needs some information to differ between standard byte property and enum like property. You can involve some naming convention to infer enums but if you really like generic solution you must modify EDMX manually and use structural annotations to tell T4 template what enum type should be used for a related property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some configuration data that I'd like to model in code as so:
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
I have a relationship in a Core Data model that feels like it wants
i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from
I have an unusual situation to model in a MS SQL Server database: the
I have an existing SQL Server database, where I store data from large specific
I have a comment model with string property like this: [Column] public string Text
I am using SQL SERVER 2005. I have a table table1(ID,col1,col2,col3,col4); Now I have
I have to use MS SQL Server 2008 to store data of PHP CAKE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.