asp.net-mvc-3 – dataannotations在主键上设置标识种子值,代码优先

ASP.NET MVC3代码一个项目.

在我的类定义中如何设置Identity种子值.

public class Account
  {
    [Key]   
    public int Id { get; set; }

将Identity种子设置为1000000的语法是什么?

谢谢

解决方法

谢谢Craig,看了 https://stackoverflow.com/a/5974656/968301后很简单.

创建一个初始化器

public class MyInitializer : DropCreateDatabaseIfModelChanges<MyContext> 
{   
  protected override void Seed(MyContext context) 
  {   
    context.Database.ExecutesqlCommand("DBCC CHECKIDENT ('Account',RESEED,1000000)");
  }  
}

然后从Global.asax.cs的Application_Start部分调用

protected void Application_Start()
{
  Database.Setinitializer(new MyInitializer());
  AreaRegistration.RegisterallAreas();

  RegisterGlobalFilters(GlobalFilters.Filters);
  RegisterRoutes(RouteTable.Routes);
}

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...