I develop my ASP.NET MVC4 app using EF Code-first, also im using Migrations feature. I have specific entity and i want to set explicit id values for some reasons. How can i do this? I tried to mark id property with attribute like this:
public class NewsSource
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
public string Title { get; set; }
public string WebSiteUrl { get; set; }
}
Then i add corresponding migration, delete database and try to update database using Seed() method like this:
context.NewsSources.AddOrUpdate(x => x.Title,
new NewsSource {Id = 654, Title = "ABC", WebSiteUrl = @"http://www.abc.com/"},
new NewsSource {Id = 22, Title = "XYZ", WebSiteUrl = @"http://XYZ.ru/"});
And ive got this error: "Cannot insert explicit value for identity column in table 'NewsSources' when IDENTITY_INSERT is set to OFF". How can i set identity_insert to ON using EF and migrations. As i understood from many topics its impossible and i have to use direct SQL-commands. Am i wrong?