How can I create an entity using EF code first that generates a table with a specific identity seed. In this case, I need the seed to be 100.
I have tried injecting the following code into the initial migration:
Sql("DBCC CHECKIDENT ('MyTable', RESEED, 100)");
The update-database command alerts me that "DBCC command 'CHECKIDENT' is not supported in this version of SQL Server", suggesting to me that CHECKIDENT is not supported for SQL Azure.
Does anyone know how to either set the seed of a new table with a data annotation, the fluent migrations api or directly through SQL?
EDIT ***
This is a restatement of the question below, but geared towards SQL Azure: EF Code First - how to set identity seed?
Independent of the target database technology, I would expected to see a far simpler solution, such as the following:
//EF Code First data annotation
//KeyAttribute would have to be unsealed
public class PrimaryKeyAttribute : KeyAttribute
{
public int Seed { get; private set; }
public int Increment { get; private set; }
public PrimaryKeyAttribute(int seed = 1, int increment = 1)
{
this.Seed = seed;
this.Increment = increment;
}
}
//Entity Primary Key Property
[PrimaryKey(100, 1)]
public int ID { get; set; }
I've searched, but I can find no such thing.
I'd even accept some sort of modification of the DatabaseGeneratedAttribute:
//Entity Primary Key Property
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity, 100, 1)]
public int ID { get; set; }
Obviously (for anyone who has used the DatabaseGeneratedAttribute) this is not possible.
If anyone knows something on this matter that I am missing, please let me know! Thanks.