2011-04-08 129 views
0

我是新與EF,但我有很多的experiance與SQL 我特林做的非常簡單的插入實體框架自我跟蹤

我有兩個表人士及地址,關係是1對多的EDMX創建兩者之間的導航屬性。

讓我說我有人,我想添加地址。

 Person p = GetPesron(); // OK 

    var newAddress = new Address {Id=1,City="ddd", Person =p}; 

    context.Addres.AddObject(d); 
    context.SaveChanges(); 

很簡單,但沒有工作,得到錯誤時拋出 無法插入標識NULL表地址!!!!!!我發送id = 1的 。 任何其他方式前:applay更改Person.Address()仍然相同的錯誤 我在這裏失蹤?

請指點 感謝

+0

在你的問題中發佈他的例外可能也有幫助。 – Extrakun 2011-04-08 08:52:02

+0

沒有關於Address.Id映射的信息,我們幾乎無法幫助您。 Id的屬性中StoreGeneratedPattern的值是什麼? – 2011-04-10 10:50:11

回答

0

也許ObjectContext.DetectChanges()可以幫助你。