2015-10-20 67 views
1

在我的項目中,我使用Entity framework 6和Breeze來獲取數據。 在客戶端,我創造處於修改狀態微風實體,如下圖所示,在實體框架中使用breeze通過id(主鍵)更新數據庫記錄6

var entity = manager.createEntity(entityName); 

entity.entityAspect.setModified();//Modifying the state 

entity.Id(id);//pushing existing primary key value 

entity.IfInactive(true); //updating the record value from false to true 

saveChanges(msg).then(function() { //calling save changes 
    console.log('Success.'); 
}); 

但在調用SaveChanges這是給喜歡「的屬性‘ID’的原始值異常,不能設置,因爲該屬性是部分實體的關鍵。「

在此先感謝!

回答

1

你需要使用一個initializer設置鍵的值在創建時的實體:您的回覆

var entity = manager.createEntity(entityName, { Id: id }); 
+0

感謝。 我已經使用該代碼,但現在它向我顯示異常,如 「{」UPDATE語句與FOREIGN KEY約束衝突\「FK__Following__TestId__76D69450 \」衝突。衝突發生在數據庫\「TestDB \」,表\「dbo.TestTable \」,列'Id'。\ r \ n該語句已被終止。「}」。 – Pankajya

+0

因此,我創建實體爲 breeze.manager.createEntity(Table_Name,{Id:id},breeze.EntityState.Unchanged); 所以現在它工作正常。 非常感謝你...... – Pankajya

+0

大家好, 我發現了上述問題的解決方案,但我仍然想知道爲什麼發生與實體框架6和breeze-client v 1.5的確切原因0.4? 當我在那時使用EF5和老版本的breeze-client時,這種問題沒有發生。 如果可能請親切地告訴我它的原因。 感謝你! – Pankajya