entity-framework-4.3 - Entity Framework 迁移未检测模型更改

标签 entity-framework-4.3 entity-framework-migrations

我正在尝试开始将 EF 迁移与现有数据库结合使用。

启动项目是一个 MVC 3 项目,域对象位于同一解决方案的单独项目中。

以下是我采取的步骤:

Add-Migration InitialMigration -IgnoreChanges -Verbose

已创建 Configuration.cs 和 ###_InitialMigration.cs。必须编辑 Configuration.cs 以添加我的上下文对象的名称,因为它位于单独的项目中。

Update-Database

已将 dbo.__MigrationHistory 添加到我的数据库

Added a new property to an existing class

private ulong? myProp;
[DataMember]
public ulong? MyProp
{
    get { return myProp; }
    set
    {
        if (myProp != value)
        {
            myProp = value;
            RaisePropertyChanged(() => this.MyProp);
        }
    }
}

成功编译解决方案。

Add-Migration MyNewMigration

创建了###_MyNewMigration.cs,其中没有迁移:

public partial class MyNewMigration : DbMigration
{
    public override void Up()
    {
    }

    public override void Down()
    {
    }
}

看起来不太好...迁移在哪里?

Update-Database -Verbose -Script

升级脚本中没有提及新属性

INSERT INTO [__MigrationHistory] ([MigrationId], [CreatedOn], [Model], [ProductVersion]) VALUES ('201206122137444_MyNewMigration', '2012-06-12T22:07:49.170Z', 0x1F8B080YadaYada, '4.3.1')

如何让 EF Migrations 接受模型更改?

最佳答案

事实证明,EF 迁移不喜欢我使用的 ulong? 数据类型。该属性在没有任何警告的情况下被忽略。

将类型更改为 long? 允许迁移成功。

关于entity-framework-4.3 - Entity Framework 迁移未检测模型更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11005646/

相关文章:

c# - 如何在 Entity Framework 数据上下文中的属性名称中使用 sql 保留关键字?

entity-framework - Entity Framework - 重新开始 - 撤消/回滚所有迁移

c# - Entity Framework 中 "The RelatedEnd cannot be returned by this RelationshipManager"异常的根本原因是什么?

c# - Entity Framework 6 尝试在重命名时删除不存在的索引

visual-studio-2015 - Visual Studio 组件缓存过期

c# - EF 不延迟加载 View

casting - ICollection 上的 MinLength 约束失败, Entity Framework

c# - 一对多关系在 EF 中不起作用

entity-framework-5 - EF5 迁移种子 AddOrUpdate 具有可为空的选择标准

c# - 使用 Entity Framework 在代码优先迁移中有条件地插入数据