小编Jor*_*iss的帖子

使用EF 4.3迁移添加TimeStamps

我正在使用Code First Migrations,我正在改变我的模型,以便为我的表添加时间戳字段.我正在尝试在第二次迁移中添加timetamp字段.以下是我的代码的示例

public class User {
    public int UserId { get; set; }
    public string UserName { get; set; }      
    public byte[] TimeStamp { get; set; }
}

 public class UserModelConfiguration: EntityTypeConfiguration<User> {
        public UserModelConfiguration() {
            Property(p => p.UserName).IsRequired().HasMaxLength(250);
            Property(p => p.TimeStamp).IsRowVersion();            
        }
    }
Run Code Online (Sandbox Code Playgroud)

生成的迁移看起来像这样

public override void Up()
        {                
            AddColumn("Users", "TimeStamp", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
        }
Run Code Online (Sandbox Code Playgroud)

当我执行Update-Database命令时,收到一条错误消息 "无法在数据类型时间戳的列上创建默认值.表'用户',列'TimeStamp'.无法创建约束 "我移动了所有数据表,但没有解决问题.

如何向此迁移集添加时间戳字段?

.net entity-framework ef-migrations entity-framework-4.3

3
推荐指数
1
解决办法
1646
查看次数