2
我有一些行動來保存我的DbContext。EntityFramework上下文不保存
我有兩個實體 - 材質和顏色。這些實體有多對多的關係。
我嘗試這樣做:
var color = context
.Colors
.Include("Materials")
.Where(g => g.Id == (colorId))
.FirstOrDefault();
var mater = context
.Materials
.Include("Colors")
.SingleOrDefault(c => c.Name == material.Name);
mater.Colors.Add(color);
context.SaveChanges();
當程序試圖運行context.SaveChanges()
,它拋出一個異常DbUpdateException
Unable to update the EntitySet 'MaterialColors' because it has a
DefiningQuery and no <InsertFunction> element exists in
the <ModificationFunctionMapping> element to support the current operation.
如何解決呢?
哪個數據庫? EDMX模型? – JotaBe
數據庫是Sql 2008 express。 ModelFirst – LuckSound
這是模型中的一個奇怪問題。 MaterialColors表的外觀如何?它只有兩個FK做PK嗎? – JotaBe