2011-09-27 75 views
0

我必須將我的應用程序從.net 4降到3.5才能讓它在我們的服務器上運行。 :(在EF1(asp.net 3.5)中設置外鍵值

反正EF「獨立協會」 - http://blogs.msdn.com/b/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx

...但現在我無法弄清楚如何設置一個外鍵的值,因爲它不再出現在我的實體

任何人都可以建議我怎樣才能做到這一點嗎?

+0

可能重複http://stackoverflow.com/questions/480872/entity-framework-setting-a-foreign-key-property –

回答

0

AFAIK,你不能直接設置值,但必須使用導航屬性,所以如果你有一個父行你想設置的外鍵爲15 ,它看起來像這樣:

var Child = (from c in context.Children 
      where id = 15).Single(); 
Parent.Child = Child; 
context.SaveChanges();