I have a simple model record with a key "Id" that I'm adding to a EF Entity. It worked through Core 2.1 but now fails with the error:
SqlException: Cannot insert explicit value for identity column in table 'SpeakerRecs' when IDENTITY_INSERT is set to OFF.
The Model is defined as follows:
namespace WebAppCore.Models
{
public class SpeakerRec
{
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string ImageUrl { get; set; }
}
}
The Code that does the insert is this and it fails on the save changes call.
foreach (var speaker in speakerRecs)
{
_context.SpeakerRecs.Add(speaker);
}
_context.SaveChanges();
I see notes about breaking changes in Core 3 and the problem is somehow around ValueGeneratedNever() but can't figure it out. I've not used EF for a while and was not planning on re-learning it. I was hoping my old code would continue to work.