How can I update DB using EF associations
I have this db model:
And I am trying to update the table GROUP
.
This is my code:
using (var ctx = new TestModelContainer())
{
ctx.GROUP.Add(new GROUP { Name = "Group 1", TEACHER = new TEACHER{FIO = "123", Email = "123@example.com"}});
ctx.SaveChanges();
}
And after the line ctx.SaveChanges()
I get an exception. What am I doing wrong? Please help me.
Mistake:
An unhandled exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll
Additional information: An error occurred while updating records. See Inner Exception for details.
Inner Exception:
Unable to insert NULL value into column "FIO", table "u399991.dbo.TEACHER"; the column does not allow zeros. INSERT fails
+3
source to share