C# Entity Framework should we set a relationship by using the POCO.Id or just the POCO?

落爺英雄遲暮 提交于 2019-12-06 03:42:36

It makes more sense to use the currency object, not just the Id because when you retrieve data you will most likely want to have the Currency property and not just the Id. When you create / update you will have the Id available in both scenarios.

I think you need to attach the currency to the target ObjectContext. If doing so, you'll see the relationship between the order and the currency without the code above. It is regarded as the order is already attached to the ObjectContext.

//if the context is the target `ObjectContext`, then
context.Currencies.Attach(currency);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!