小编Ale*_*fel的帖子

实体框架代码优先迁移的例外情况

在使用Entity Framework 4.3的Code First Migrations时,我得到了几个未处理的异常.

数据库上下文:

public class MyAppContext : DbContext
{
   public DbSet<Branch> Branches { get; set; }

   public MyAppContext()
   { }
}
Run Code Online (Sandbox Code Playgroud)

实体:

public class Branch : IEntity<Guid>
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public bool Active { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

数据库初始化程序:

public class MyAppInitializer : CreateDatabaseIfNotExists<MyAppContext>
{
   protected override void Seed(MyAppContext context)
   {
      context.Branches.Add(new Branch() { Id = branchId, Name …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework ef-migrations

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

ef-migrations ×1

entity-framework ×1