How can I update DB using EF associations

I have this db model:

enter image description here

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


1 answer


Through what you've provided, you can try this:



Insert a non-null value for the column, or you can make sure your column is nullable.

0


source







All Articles