We use Entity Framework. And I have an issue with a table in the DB.
The Id is a GUID
where we create a new GUID
manually.
Now I want to implement a new column to auto increment and I want this to start at 100000000.
To make the column auto increment is working ok (I think)
Company {
private Guid id = Guid.NewGuid();
[Required, Range(10000000, 999999999)]
[Index(IsUnique = true)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual long StakeholderNumber
{
get;
set;
}
}
When adding the migration, I get this migrationfile;
public override void Up()
{
AlterColumn("dbo.Companies", "StakeholderNumber", c => c.Long(nullable: false, identity: true));
CreateIndex("dbo.Companies", "StakeholderNumber", unique: true);
}
public override void Down()
{
DropIndex("dbo.Companies", new[] { "StakeholderNumber" });
AlterColumn("dbo.Companies", "StakeholderNumber", c => c.Long(nullable: false));
}
This looks to work.
BUT I want the stakeholderNumber to start at 100000000 instead of 1.
From other examples, this could work by setting stakeholdernumber to primary
and then add the line:
Sql("DBCC CHECKIDENT ('dbo.Companies', RESEED, 100000000);");
BUT I do not want stakeholdernumber to be primary
!
If I run this with updadte-database, I get this error:
Companies' does not contain an identity column
SO is there a way to set auto increment on Stakeholdernumber to 10000000 without making the column primary
?