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 5937681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:34:36+00:00 2026-05-22T15:34:36+00:00

I am trying to save an Enum that exists in my model down to

  • 0

I am trying to save an Enum that exists in my model down to the database but everytime I do Entity Framwework complains that there is no look up table associated with the Enum. I do not want a look up table, I just want the enum to exist in code and be stored as integers in the database.

An error occurred while saving
entities that do not expose foreign
key properties for their
relationships. The EntityEntries
property will return null because a
single entity cannot be identified as
the source of the exception. Handling
of exceptions while saving can be made
easier by exposing foreign key
properties in your entity types. See
the InnerException for details.

“Cannot insert the value NULL into
column ‘Type’, table
‘Test.dbo.Interests’; column
does not allow nulls. INSERT
fails.\r\nThe statement has been
terminated.

The value for Type is definitely not null, EF just treats it that way cause it can’t find a Foreign key table that I don’t want in the first place.

How do I get entity framework to treat my enum as an int and then convert back out when I call down to the database to retrieve my model?

  • 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-22T15:34:37+00:00Added an answer on May 22, 2026 at 3:34 pm

    Entity framework doesn’t support enums at all so you cannot map enum property to the database. You must use int property instead and if you want enum as well you must define another not mapped property (in case of autogenerated entities you must define it in your partial class) which converts int to enum.

    Edit:
    Enum support was added in later version. If you want to map enums (integer values, not strings at the moment) you need to use .NET 4.5 and EF5 or EF6.x and .NET 4.x.

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

Sidebar

Related Questions

I am trying to save data to a database on a button push, but
I'm trying to save a simple object in the database, but it's giving me
Hello I'm trying to save string into SQLite database, but nothing happens. I have
I am trying to save a model with its dependency models being saved. Model1
I am trying to save drafts using NSUserDefaults but I am not sure if
I'm trying to save a binary file stored in a SQL database with a
I'm trying to save a new object from a django model using a POST
I am trying to save a BLOB created from an integer array (that is,
I'm trying to save a file at path WindowsFormsApplication1\WindowsFormsApplication1\SaveFile but the following code returning
I am trying to save two models to the database. USER and BOARD. I

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.