EF - Cannot insert the value NULL into column 'Id'
I have this entity:
I try to autofixture excluding the id but i dont think that works because its int so it will always default to 0 ? - fact check me pls
but the db should be handling generating its id, why do i get this error running the following test ?
Microsoft.Data.SqlClient.SqlException Cannot insert the value NULL into column 'Id', table 'pas.dbo.CorrespondenceAddress'; column does not allow nulls. INSERT fails.
and here is the live auto fixtured entity copied in rider:
4 Replies
those 2 attributes on Id are implicit
whats
Policy
It's okay I got it resolved with the following added to the OnModelCreate instead
modelBuilder.Entity<CorrespondenceAddress>().Property(c => c.Id).HasDefaultValue(0);
$close
If you have no further questions, please use /close to mark the forum thread as answered