I am creating an asp.net mvc4 site using a framework 5 entity with codefirst and sql server express 2012.
I have enabled migration and am now doing this in my Configuration.Seed: (note that I want to set the primary key to 8, even if this is the first record in the database).
context.ProductCategoryDtoes.AddOrUpdate(x => x.Id, new ProductCategoryDto() { Id = 8, Name = "category1" } );
The My Model object is defined as follows:
[Table("ProductCategory")] public class ProductCategoryDto { public long Id { get; set; } public string Name { get; set; } }
This results in a table in (SQL SERVER EXPRESS 2012), where the Id column has Identity = true, Identity seed = 1, identifier increment = 1.
Now, when I start the migration, doing PM> Update-Database this result in a line with Id = 1.
So my question is:
1) How can I control the values ββof automatically increasing primary keys when sowing data.
2) If the solution is to increase the initial value of the key columns, how to do it when I use Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>()); . This will nuke and rebuild the database every time I update the database, so how will the seed value in the new database be updated?
source share