我生成了一个新的Migration,但由于某种原因,它删除了我正在使用的所有枚举,并且不在db模式中添加任何对它的支持。虽然它是在Code-First中定义的
这些是我的枚举:
using System;
namespace StockManagement.Enums
{
public enum InventoryMethod
{
FIFO = 0,
LIFO = 1,
WEIGHTED_AVERAGE = 2
}
public enum TransactionDirection
{
BUY = 0,
SELL = 1
}
}
这是我的2个相关课程:
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; }
}
这是我生成的迁移:
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; }
}
我有EF 5.0,最近没有改变:) 任何人都知道为什么会突然发生这种情况以及如何解决这个问题?
答案 0 :(得分:1)
大多数数据库没有枚举概念。这反映在EF中,其中枚举属性由相应枚举类型的基础类型的列支持。例如,因为InventoryMethod类型的基础枚举类型是System.Int32 / int(如果未指定特定的基础类型,则它是默认的基础类型)此类型的所有属性都将由int类型的列支持(C#maps中的int到EDM中的Edm.Int32,它又映射到数据库中的int(我在这里谈论的是Sql Server))。