3
协会我有这个DB模式更新DB:我怎么能与EF
我试图更新GROUP
表。
这是我的代码:
using (var ctx = new TestModelContainer())
{
ctx.GROUP.Add(new GROUP { Name = "Group 1", TEACHER = new TEACHER{FIO = "123", Email = "[email protected]"}});
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
错误是什么?你是否也需要添加一个人? – 2014-10-28 15:28:32
@TMcKeown no。我不需要添加人员。错误添加到帖子。 – EXTRAM 2014-10-28 15:29:23
您正试图将一个空值插入到不允许空值的列中,并将值传递给它所设置的数据类型。 possbile重复http://stackoverflow.com/questions/18956579/cannot-insert-the-value-null-into-column-table-column-does-not-allow-nulls – Haris 2014-10-28 15:39:24