1

This is my configuration where my primary key column is NetworkId and it's DatabaseGeneratedOption is Identity.

public NetworkConfiguration() : base()
{
   this.HasKey(e => e.NetworkId);
   Property(e => e.NetworkId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
}

This value starts from 1 always can I make it to start with 0?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
srinivas rao
  • 43
  • 1
  • 6
  • 1
    Check out [EF Code First - how to set identity seed?](http://stackoverflow.com/q/5974554/1931491), [How do I set Identity seed on an ID column using Entity Framework 4 code first with SQL Compact 4?](http://stackoverflow.com/q/11732102/1931491), [Setting the seed value for an identity column in visual studio/entity framework w/SQL Server 2008R2](http://stackoverflow.com/q/4051459/1931491) – bwdeng Dec 29 '12 at 11:08

2 Answers2

0

In MVC 3 and EF 4.1 you could try something like this:

context.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('NetworkConfiguration', RESEED, 0)");

followed by the method that populates your table with the rest of the values

SeedNetworkConfiguration();
hatsrumandcode
  • 1,871
  • 2
  • 19
  • 21
-3

Database ids will always start at 1. Out of interest, why would you want an id to be 0?

Greg Smith
  • 2,449
  • 2
  • 24
  • 37
  • We need to start it from 0, because our project entities start from 0 – srinivas rao Dec 29 '12 at 10:57
  • Ok - to be honest, I don't know if you can start it at zero or not, but having a row in the database with an identifier of 0 to me sounds like a bad idea. – Greg Smith Dec 29 '12 at 11:01