2011-09-27 66 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();