How to insert an entity with ID in Entity Framework 6.0? That is, insert with ID because the table does not generate it. For example:
var last = _contexto.Area.AsEnumerable().LastOrDefault();
area.Id = last !=null ? last.Id + 1 : 1;
_contexto.Entry(area).State = EntityState.Added;
_contexto.SaveChanges();
However, the following exception is thrown:
System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. --- > System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. --- > System.Data.SqlClient.SqlException: Can not insert the value into column 'Id', table 'SIPP.dbo.Area'; column does not allow nulls.