EF code首先 - 如何设置标识种子? [英] EF Code First - how to set identity seed?

查看:701
本文介绍了EF code首先 - 如何设置标识种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体类

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.

这篇关于EF code首先 - 如何设置标识种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆