EF and timestamp column cannot update / execute

I have an object in EF6 that I forgot to inherit from my auditableEntity class. This class has this configuration

public abstract class AuditableEntityConfig<TEntity> : BaseEntityConfig<TEntity> where TEntity : AuditableEntity
{
    public AuditableEntityConfig()
        : base()
    {

        this.Property(e => e.RowVersion)
            .IsRowVersion();

    }
}

Now I updated my object to inherit this class, and now, after running my code, I always get an error

Cannot alter column 'RowVersion' to be data type timestamp.

Anyway, can I stop EF by trying to set this column as a timestamp, and maybe I will close and re-create the table instead?

+4
source share
2 answers

Step 1. Change the definition of the mannualy table:

   [RowVersion]   TIMESTAMP NOT NULL

Step 2. Go to NameOfMigrationAdded.cs in the Migrations directory and comment on this line in the Up () method:

   AlterColumn("dbo.YOUR_TABLE_NAME_HERE", "RowVersion", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));

3. " " PM

;)

4. Up(), :

 Version = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),

CreateTable (...) AddColumn (...)

:

  AddColumn("dbo.Rows", "RowVersion", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
+2

AlterColumn DropColumn AddColumn Up().

        public override void Up()
        {
            DropColumn("dbo.Cities", "RowVersion", null);
            AddColumn("dbo.Cities", "RowVersion", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
        }

        public override void Down()
        {
            AlterColumn("dbo.Cities", "RowVersion", c => c.Binary());
        }
+2

All Articles