我有一个实体类
public class Employee
{
public long Id { get; set; }
public string Name { get; set; }
}
我已经设置了标识字段与自动编号生成主键
I have set the Id field as the primary key with auto number generation
modelBuilder.Entity<Employee>().HasKey(e => e.Id);
modelBuilder.Entity<Employee>().Property(e => e.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
但我想的身份到10000,而不是从1这是默认的种子。我怎样才能在EF指定此?
But I want the Identity to seed from 10000 instead of from 1 which is the default. How can I specify this in EF?
如果您使用的是SQL Server,则必须创建自定义数据库的初始化和手动执行 DBCC CHECKIDENT('TableName中,RESEED,NewSeedValue)
。创建和使用自定义的初始化与自定义SQL命令检查这个答案。
If you are using SQL Server you must create custom database initializer and manually execute DBCC CHECKIDENT ('TableName', RESEED, NewSeedValue)
. For creating and using custom initializer with custom SQL commands check this answer.