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

  • SEARCH
  • Home
  • 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 8371587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:11:55+00:00 2026-06-09T14:11:55+00:00

Let’s say we have the following simple model: public class Car { public int

  • 0

Let’s say we have the following simple model:

public class Car
{
    public int Year { get; set; }
    public string Make { get; set; }
    public string Model { get; set; }
    public CarType Type { get; set; }
}

public enum CarType
{
    Car, Truck
}

Entity Framework, when adding a new Car object to the database, will store the CarType enum value as an integer.

If we change the CarType enum in a way where the integer values change (change the order or add/remove values), does Entity Framework know how to properly handle the data migration using Migrations?


For example, let’s say we added another value to CarType:

public enum CarType
{
    Car, Truck, Van
}

This would have no real effect on the existing data in the database. 0 is still Car, and 1 is still Truck. But if we changed the order of CarType, like this:

public enum CarType
{
    Car, Van, Truck
}

Database records with 1 as the CarType to designate Truck would be incorrect, since according to the updated model 1 is now Van.

  • 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-06-09T14:11:56+00:00Added an answer on June 9, 2026 at 2:11 pm

    No, Migrations does not fully support enum changes since it does not update the database values to reflect changes such as altered order, additions or removals.

    Adding enum values while preserving the order will have no effect. In fact, it will not even fire a model backing change error.

    If the order of the CarType enum changes, then the database data will effectively be invalid. The original int values are preserved, but the enum results will be wrong.

    In order to accommodate this type of change, manual processing of the database data will be necessary. In this specific example, custom SQL will have to be run that changes the values of the Type column according to the enum changes:

    public partial class CarTypeChange : DbMigration
    {
        public override void Up()
        {
            // 1 now refers to "VAN", and 2 now refers to "Truck"
            Sql("Update cars Set [Type] = 2 Where [Type] = 1");
        }
    
        public override void Down()
        {
            Sql("Update cars Set [Type] = 1 Where [Type] = 2");
        }
    }
    

    Addendum: I’ve asked another question related to this: Handling enum changes in Entity Framework 5

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

Sidebar

Related Questions

Let's say I have the following classes : public class MyProductCode { private String
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following type type Key = String type Score =
Let's say I have an string variable called *magic_string* which value is set to
Let's say I have a class Base with a single member message (String). Another
Let me explain best with an example. Say you have node class that can
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:

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.