使用多个 edmx 文件与使用一个大 edmx 文件?
我是实体模型的新手,我正在寻找如何组织我的实体模型的建议。
我应该创建一个实体模型文件(.edmx),其中包含数据库中的所有表,还是应该将其分解为用户、订单、产品等的逻辑文件。
请让我知道哪一个更好以及优点/缺点(如果有)每个替代方案。
谢谢。
I'm new to the Entity model thing and i'm looking for an advise how to organize my Entity model.
should i create one entity model file (.edmx) which will contain all the tables in my database or should i break it logical files for user, orders, products, etc.
Please let me know which one is better and what the pros/cons (if any) of each alternative.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我要违背这里的原则。我现在已经使用 EF 构建了 2 个大型应用程序,一个使用单个 edmx,另一个使用多个。有优点也有缺点,但总的来说,我发现使用一台 edmx 会让生活变得更轻松。原因是应用程序内几乎从来没有真正的域分离,即使从一开始就存在这种情况。弹出的新要求要求您关联不同 edmx 中的实体,然后您必须重构并不断移动事物。
当 EF 5 引入了多个图表,这是首先划分 edmx 文件的唯一真正好处。您不想看到您未处理的所有内容,也不希望性能受到影响。
在我的带有分割 edmx 的应用程序中,我们现在有一些重复的实体来获得导航属性的好处。也许您的应用程序具有真正的域分离,但通常所有内容都与用户相关。我现在正在考虑合并其中的两个,但这需要大量工作。所以我想说,让他们待在一起,直到出现问题为止。
I'm going to go against the grain here. I've built 2 large applications with EF now, one with a single edmx and one with several. There are pros and cons but generally I found life to be much easier with one edmx. The reason is that there is almost never a real separation of domains within an app, even if there appears to be from the start. New requirements pop up asking you to relate entities in different edmx's then you have to refactor and continually move things around.
All arguments for dividing will soon be obsolete when EF 5 introduces Multiple Diagrams, which is the only real benefit for dividing edmx files in the first place. You don't want to have to see everything you're not working on and you don't want a performance impact.
In my app with the divided edmx's we now have some duplicate entities to get the benefit of navigation properties. Maybe your app has a true separation of domains, but usually everything connects to the user. I'm considering merging two of the now but it will be a lot of work. So I would say keep them together until it becomes a problem.
使用一个包含所有实体的大型 EDM 通常不是一种好的做法,也不建议这样做。您应该提出不同的领域模型集,每个域模型都包含相关对象,而每个集都是不相关的并且与另一个集断开连接。
看一下这篇文章,我详细解释了这个问题:
为所有实体创建一个图表有意义吗?
Having one big EDM containing all the entities generally is NOT a good practice and is not recommended. You should come up with different sets of domain models each containing related objects while each set is unrelated and disconnected from the other one.
Take a look at this post where I explained this matter in detail:
Does it make sense to create a single diagram for all entities?
我认为我们应该在项目中保留多个 edmx 文件。它就像 1-edmx 文件——一个聚合(相关对象的集合)。根据 ddd(域驱动设计),我们的模型中可以有多个聚合。我们可以为每个聚合保留一个 edmx 文件
i think we should keep multiple edmx files in our project. it's like 1-edmx file -- one aggregate (collection of related objects). as per ddd (domain drive design) we can have more than one aggregates in our model. we can keep one edmx file for each aggregate