0

问候,

我有迁移和二进制字段的问题......

我的初始迁移如下所示(我有一个现有的数据库):

public override void Up()
{
    CreateTable("dbo.Words", c => new
    {
        ID = c.Int(nullable: false, identity: true),
        Name = c.String(maxLength: 4000),
        Image = c.Binary(),
        Audio = c.Binary(),
    }).PrimaryKey(t => t.ID);
}

实体类在这里:

public class Word
{
    public int ID { get; set; }
    public string Name { get; set; }
    [MaxLength]
    public byte[] Image { get; set; }
    [MaxLength]
    public byte[] Audio { get; set; }
}

我打开了自动迁移。现在,如果我从数据库中删除所有表并运行“Update-Database”,我会得到:

Applying code-based migration: 201304211813502_InitialMigration.
Applying automatic migration: 201304212024538_AutomaticMigration.
System.Data.SqlServerCe.SqlCeException (0x80004005): Cannot alter column of type NTEXT or IMAGE [ Column Name = Image ]

所以看起来有些东西不同步。我运行“Add-Migration AutoMigration”来查看它所考虑的实体框架仍然需要更新......我得到的文件在这里:

public partial class AutoMigration: DbMigration
{
    public override void Up()
    {
        AlterColumn("dbo.Words", "Image", c => c.Binary());
        AlterColumn("dbo.Words", "Audio", c => c.Binary());
    }

    public override void Down()
    {
        AlterColumn("dbo.Words", "Audio", c => c.Binary(maxLength: 4000));
        AlterColumn("dbo.Words", "Image", c => c.Binary(maxLength: 4000));
    }
}

所以......从这里看起来EF认为图像和音频字段是二进制(最大长度:4000)......但他们不应该是!(因为在初始迁移中它们是Binary())。

所以我被卡住了,无法更新我的迁移......我需要 MaxLength(无限)二进制字段......

这里会发生什么?谢谢你!大卫

4

1 回答 1

0

我终于设法将项目升级到 EF 6.0.0 Alpha3 ...我必须修复很多小问题,并将 NuGet 升级到 2.5 RC。现在它可以工作了..不确定我做了什么,但很可能只是升级到 EF 6

于 2013-04-24T17:24:41.713 回答