实体框架中两个上下文之间的继承
我在一个 dll 中有一个 edmx,并且需要在另一个 dll 的 edmx 中拥有一个从第一个 edmx 中的实体继承的实体。我尝试用第二个 edmx 扩展第一个 edmx 的初始上下文,但没有成功。实现这一目标的最佳方法是什么?
I have one edmx in one dll, and need to have an entity in an edmx in another dll inherit from an entity in the first edmx. I have attempted to extend the initial context of the first edmx with the second with no success. What is the best way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那是不可能的。一个 EDMX = 一个
ObjectContext
并且它们之间没有继承。我发现了一个特殊黑客如何强制上下文加载多个EDMX,但它们必须位于同一程序集中,并且仅适用于跨 EDMX linq-to-entities 查询。我认为您必须在第二个 EDMX 中再次对整个继承层次结构进行建模,并为父级重用相同的 POCO 类 = 父实体必须位于两个 EDMX 中。查看有关使用多个模型的这些文章 (第 1 部分,
That is not possible. One EDMX = one
ObjectContext
and no inheritance among them. I found a special hack how to force context to load multiple EDMXs but they must be in the same assembly and it works only for cross EDMX linq-to-entities queries.I think you must model whole inheritance hierarchy again in the second EDMX and reuse same POCO class for the parent = parent entity must be in both EDMXs. Check these articles about working with multiple models (part 1, part 2). There is possibility to reusing CSDL types from one EDMX in other EDMX for defining associations but it will not work for inheritance because inheritance is defined in MSL which cannot be reused.
继承可能不是最好的解决方案。我建议从不同程序集的两个实体进行依赖注入,例如:
Inheritance may not be the best solution for this. I would suggest dependency injection from both entities from separate assemblies, e.g.: