2014-10-28 56 views
3

協會我有這個DB模式更新DB:我怎麼能與EF

enter image description here

我試圖更新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

+0

錯誤是什麼?你是否也需要添加一個人? – 2014-10-28 15:28:32

+0

@TMcKeown no。我不需要添加人員。錯誤添加到帖子。 – EXTRAM 2014-10-28 15:29:23

+0

您正試圖將一個空值插入到不允許空值的列中,並將值傳遞給它所設置的數據類型。 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

回答

0

通過您所提供的東西,你可以嘗試以下方法:

插入一個非空值的列,也可以確保您的列接受空值。