好的,這真的很奇怪。我用一個單一表格Customer做了一個簡單的數據庫,它有一個單列Name。從數據庫I自動生成一個ADO.NET實體數據模型,和我想要一個新客戶添加到它,像這樣:無法使用實體框架更新數據庫中的行...?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
class Program
{
static void Main()
{
Database1Entities db = new Database1Entities();
Customer c = new Customer();
c.Name = "Harry";
db.AddToCustomer(c);
db.SaveChanges();
}
}
}
但它不堅持客戶「哈利」到數據庫!我一直在撓頭,現在想知道爲什麼這樣一個簡單的操作不起作用。究竟什麼是問題!?
沒有主鍵?沒有自動生成的標識列?嘗試添加INT ID,身份,主鍵到您的表,以便EF有一個EntityKey。 – 2010-05-15 17:03:06
名稱是主鍵。但爲了你的緣故,我嘗試使用ID列作爲主鍵,但這也不起作用! – Dissonant 2010-05-15 17:11:53
如果你在一個try .... catch ....塊中包裝這個 - 你是否會遇到任何異常,如果是的話 - 什麼異常? – 2010-05-15 20:37:19