开发者

What fluent api method is correspond to 1678280971 attribute in Data Annotations API to check concurrency

I am using Entity Framework 4.1. What fluent api method开发者_开发技巧 is correspond to 1678280971 attribute in Data Annotations API to check concurrency?


If you have class like this:

public class MyEntity
{
    ...
    public byte[] Timestamp { get; set; }
}

You will use fluent mapping like this:

modelBuilder.Entity<MyEntity>()
            .Property(e => e.Timestamp)
            .IsConcurrencyToken()
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);

Or:

modelBuilder.Entity<MyEntity>()
            .Property(e => e.Timestamp)
            .IsRowVersion();              


You can use code as Ladislav Mrnka described, but

There are small differences between :

modelBuilder.Entity<MyEntity>()
            .Property(e => e.Timestamp)
            .IsConcurrencyToken()
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);

and

modelBuilder.Entity<MyEntity>()
            .Property(e => e.Timestamp)
            .IsRowVersion();   

second is equivalent of 1678280971 attribute, but first generates the following migration, when we change '1678280971` to first version of fluent API code:

    public override void Up()
    {
        AlterColumn("dbo.MyEntity", "Timestamp", c => c.Binary());
    }

    public override void Down()
    {
        AlterColumn("dbo.MyEntity", "Timestamp", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜