I'm trying to create an object by manually inserting the primary key, but it's not possible the way I have it. I tried to put the ExecuteSqlCommand()
but it doesn't exist.
I check this https://stackoverflow.com/a/43973327/13954475 but that didn't solve my problem.
I have this:
public void CreateYear(int yearId)
{
try
{
Year year = new Year();
year.YearId = yearId;
year.YearAcademic = yearId.ToString() + "/" + (yearId + 1).ToString();
year.IsActive = false;
_context.Database.ExecuteSql($"SET IDENTITY_INSERT dbo.Years ON");
_context.Years.Add(year);
_context.SaveChanges();
_context.Database.ExecuteSql($"SET IDENTITY_INSERT dbo.Years OFF");
}
catch
{
throw;
}
}
I also tried with ExecuteSqlRaw
and others.