I have an object in EF6 that i forgot to inherit from my auditableEntity class. This class has a configuration like so
public abstract class AuditableEntityConfig<TEntity> : BaseEntityConfig<TEntity> where TEntity : AuditableEntity
{
public AuditableEntityConfig()
: base()
{
this.Property(e => e.RowVersion)
.IsRowVersion();
}
}
Now i have updated my entity to inherit from this class and now upon running my code, i always get an error saying
Cannot alter column 'RowVersion' to be data type timestamp.
Is there anyway i can stop EF trying to set this column to be timestamp, and maybe i drop and recreate the table myself instead?
Replace one line
AlterColumn
with 2 linesDropColumn
andAddColumn
in Up() method.
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());
}
Step 1. Edit table definition mannualy:
[RowVersion] TIMESTAMP NOT NULL
Step 2. Go to NameOfMigrationAdded.cs in Migrations directory and comment this line in Up() method:
AlterColumn("dbo.YOUR_TABLE_NAME_HERE", "RowVersion", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
Step 3. Run 'Update-Database' command in PM console
Now it works ;)
Step 4. Return to previous migration and edit Up() method by adding:
Version = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
in CreateTable( ... ) or AddColumn( ... )
Ex:
AddColumn("dbo.Rows", "RowVersion", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With