我在使用代码优先方法在sql Compact 4中的Id列上设置Identity Seed时遇到了一些问题.
我试过这个
context.Database.ExecutesqlCommand("DBCC CHECKIDENT ('Members',RESEED,100001");
但这在sql Compact中不起作用.
MyDbContext:
protected override void OnModelCreating(DbModelBuilder modelBuilder) { SetupMemberEntity(modelBuilder); } private static void SetupMemberEntity(DbModelBuilder modelBuilder) { modelBuilder.Entity<Member>().Property(m => m.Id); //.Property(m => m.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); modelBuilder.Entity<Member>().Property(m => m.FirstName).Isrequired(); modelBuilder.Entity<Member>().Property(m => m.LastName).Isrequired(); modelBuilder.Entity<Member>().Property(m => m.PinCode).Isrequired(); modelBuilder.Entity<Member>().Property(m => m.Email); //modelBuilder.Entity<Member>().Property(m => m.DateCreated).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed); //modelBuilder.Entity<Member>().Property(m => m.DateModified).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); }
context.Database.ExecutesqlCommand("ALTER TABLE Members ADD MemberId INT IDENTITY(10000,1) PRIMARY KEY");