ORM架构:一个或多个模型(实体框架) [英] ORM Architecture: One or Multiple Models (Entity Framework)

查看:328
本文介绍了ORM架构:一个或多个模型(实体框架)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方案:

我工作的一个解决方案,有许多组件。主要组件引用DAL一大群EF模型。我的工作,它包含了自己的小EF模型中的DLL。两种型号都将连接到同一个数据库。该DLL,我的工作信息将数据返回到主组件上,但它并不一定必须从它的模型返回实体

问:

难道每个子组件包含它自己的小模型或他们都应该共享相同的大模型更好吗?

讨论:

  • 在一方面,如果我共享主组件的模型,该子组件可以返回实体到主组件。
  • 在另一方面,共用一个大模型夫妇每个组件的模型。看起来,这将增加该变更该模型可以打破一个子集的机会。我未必能够安全地使害怕破坏子组件中的一个有用的更改主力机型。

编辑:

  1. 雷Vernagus了一些很好的意见(我认为)关于在你的模型设定明确的边界值。我的真正的喜欢这个主意。那种我通过在我的组件单独的样板,因为我的子组件具有明确的范围这样做了。难道这还不够?

  2. 考虑的情况,其中所有的域模型的在同一个DAL组件与许多实体是基于相同的表并有相同的名称。除了需要是在SAPARATE的命名空间,这将是一个坏主意?

解决方案

埃里克·埃文斯介绍了这一情况正好在他的书中,的领域驱动设计。他的建议是设置在你的模型界限,明确规定其适用范围内它的范围。这就是所谓的界上下文和的上下文导航

这听起来像你需要明确你是否希望有一个共同的域模型,还是每一个DAL组件应该是有界的,以自己的模式。如果你想要一个中心域模型,你可能要考虑这样的定义在你的主组件,然后让你的DAL组件,通过这种模式与它通信。否则,你可以保持每DAL装配独立的模型,但明确定义限界上下文。

希望帮助!

Scenario:

I'm working on a solution that has many assemblies. The main assembly references a DAL assembly with a large EF model. I am working on a DLL that contains its own smaller EF model. Both models will connect to the same database. The DLL that I am working on will return data to the main assembly, but it doesn't necessarily have to return entities from its model.

Question:

Is it better for each sub-assembly to contain its own small model or should they all share the same large model?

Discussion:

  • On one hand, if I shared the main assembly's model, the sub-assembly could return entities to the main assembly.
  • On the other hand, sharing one large model couples each assembly to that model. It seems like this would increase the chance that a change to that model could break a sub-assembly. I may not be able to safely make useful changes to the main model in fear of breaking one of the sub-assemblies.

Edit:

  1. Ray Vernagus had some good points (I think) about setting clearly defined boundries around your models. I really like this idea. I am kind of doing this already by having a separate model in my subassembly, since my subassembly has a clearly defined scope. Is this enough?

  2. Consider the situation where all of the domain models were in the same DAL assembly and many of the entities were based on the same tables and had the same names. Besides needing to be in saparate namespaces, would this be a bad idea?

解决方案

Eric Evans describes this situation aptly in his book, Domain Driven Design. His recommendation is to set boundaries around your models and to explicitly define the scope within which they apply. This is known as Bounded Context and Context Map.

It sounds like you need to be explicit about whether or not you want to have one common Domain Model or whether each DAL assembly should be bounded to its own Model. If you want one central Domain Model, you may want to consider defining such in your main assembly and then have your DAL assemblies communicate with it through that model. Otherwise, you can keep to the separate models per DAL assembly but define explicit Bounded Contexts.

Hope that helps!

这篇关于ORM架构:一个或多个模型(实体框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆