I have a POCO that I am trying to create via Code First Migrations and then seed data. The problem is that I want to insert specific values into the identity column when seeding.
Here is my POCO
public class Result
{
public long ResultId { get; set; }
public long? TeamId { get; set; }
public Team Team { get; set; }
}
And here is my AddOrUpdate call in the Seed method of the Configuration.cs
context.Results.AddOrUpdate
(
r => r.ResultId,
new Result { ResultId = 101, TeamId = null },
new Result { ResultId = 201, TeamId = null }
);
As expected, it does not insert the values of 101 and 201, but instead 1 and 2. Are there any DataAttributes I can apply to the model to help with this?
Best Answer
This how to turn off Identity via attribute/conventions
This is how you turn off Identity via EntityTypeConfiguration
Or you can use the OnModelCreating overload