Getting a persistent entity reference without a DB call
Is it possible to get a reference to an already persistent object for which the id is known without a DB roundtrip, like one would do with NHibernate using ISession.Load(id)
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Yes it is possible if the object is already loaded. In case of EF Future CTP5 you can use new
Local
property of theDbSet<T>
instance:In case of
ObjectContext
the situation is little bit complicated - you needEntityKey
instance which is cumbersome to get when working with POCOs.Part of my repository code:
If the instance is not loaded you simply can't get the reference without querying DB. You can use dummy object creation.
CTP5 example:
Pure EF4 example:
or dummy object with proxy creation (CTP5 example):
CTP5 example:
Pure EF4 example: