I generated a new Migration, but for some reason, it drops all the enums i’m using and doesn’t add any support for it in the db schema. Although it is defined in Code-First
These are my enums:
using System;
namespace StockManagement.Enums
{
public enum InventoryMethod
{
FIFO = 0,
LIFO = 1,
WEIGHTED_AVERAGE = 2
}
public enum TransactionDirection
{
BUY = 0,
SELL = 1
}
}
These are my 2 relevant classes:
public class User
{
[Key]
public int UserID { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
/// <summary>
/// FIFO = First In First Out
/// LIFO = Last In First Out
/// AVG = Average
/// </summary>
public InventoryMethod InventoryMethod { get; set; }
public virtual ICollection<Article> Articles { get; set; }
}
public class ArticleTransaction
{
[Key]
public int ArticleTransactionID { get; set; }
public DateTime TransactionDate { get; set; }
/// <summary>
/// Buy = Buying goods from suppliers
/// Sell = Selling goods to customers
/// </summary>
public TransactionDirection BuyOrSell { get; set; }
public int Number { get; set; }
public double PriceExclusive { get; set; }
public virtual Article Article { get; set; }
}
This is my generated Migration:
using System.ComponentModel.DataAnnotations;
using System;
using StockManagement.Enums;
public class ArticleTransaction
{
[Key]
public int ArticleTransactionID { get; set; }
public DateTime TransactionDate { get; set; }
/// <summary>
/// Buy = Buying goods from suppliers
/// Sell = Selling goods to customers
/// </summary>
public TransactionDirection BuyOrSell { get; set; }
public int Number { get; set; }
public double PriceExclusive { get; set; }
public virtual Article Article { get; set; }
}
I have EF 5.0 and this hasn’t changed recently 🙂
Anyone has an idea on why this is suddenly happening and how to fix this?
Most databases do not have concept of enums. This is reflected in EF where an enum properties are backed by columns of underlying types of the corresponding enum types. For example because the underlying enum type of the InventoryMethod type is System.Int32/int (which is the default underlying type if no specific underlying type is specified) all properties of this type will be backed by columns of int type (int in C# maps to Edm.Int32 in EDM which in turn maps to int in the database (I am talking about Sql Server here)).