[英]insert data in no identity number column
我的數據庫中有一個表。
該表有一個名為A的列,該列不是實體或自動編號,唯一鍵或...
我使用Entity Framework 4.1從數據庫創建了一個模型。
我的密碼
using (var contex = new testEntities())
{
Table_1 t = new Table_1();
t.A = 1;
contex.Table_1.Add(t);
contex.SaveChanges();
}
我不想在表中使用標識號或索引。 當我想在其中插入一行時,出現此錯誤:
Unable to update the EntitySet 'Table_1' because it has a DefiningQuery and no
<InsertFunction> element exists in the <ModificationFunctionMapping> element to
support the current operation.
您要么必須給表一個主鍵(您似乎不想這樣做),要么需要提供一個函數來告訴Entity Framework如何將數據插入數據庫中。
我強烈建議您在表上放置一個主鍵,除非您有很好的理由不這樣做,並且在我所有的歲月中,當我想要一個沒有主鍵的表時,我想不起很多情況。
如果根本不需要主鍵,那么您可能會發現本文對使用存儲的程序將數據插入數據庫中有用: http : //msdn.microsoft.com/zh-cn/data/gg699321.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.