EF代码首先 - 如何设置身份种子? [英] EF Code First - how to set identity seed?
本文介绍了EF代码首先 - 如何设置身份种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个实体类
public class Employee
{
public long Id { get; set; }
public string Name { get; set; }
}
我已经将Id字段设置为主键, / p>
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.
这篇关于EF代码首先 - 如何设置身份种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文