我有这个数据库模型:
我正在尝试更新 GROUP
表。
这是我的代码:
using (var ctx = new TestModelContainer())
{
ctx.GROUP.Add(new GROUP { Name = "Group 1", TEACHER = new TEACHER{FIO = "123", Email = "123@example.com"}});
ctx.SaveChanges();
}
在 ctx.SaveChanges()
行之后我得到一个异常。我究竟做错了什么?请帮助我。
错误:
An unhandled exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll
Additional information: An error occurred while updating the entries. See the inner exception for details.
Inner exception:
Cannot insert the value NULL into column 'FIO', table 'u399991.dbo.TEACHER'; column does not allow nulls. INSERT fails
最佳答案
根据您提供的内容,您可以尝试以下操作:
为该列插入一个非空值,或者您可以确保您的列接受一个空值。
关于c# - 我如何更新数据库与 EF 的关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26612127/