实体框架 4 和 ddd 内的 EAV

发布于 2024-10-08 21:11:16 字数 621 浏览 0 评论 0原文

我的数据库中的一些表是使用 EAV 概念设计的。 然后,我使用 ORM 实体框架自动生成的实体并将“静态”表(不是“EAV”表)表示为 DDD 对象。

  1. 如何使用实体框架在对象模型中使用我的“EAV”实体(而不是像数据库中的关系实体)?

例如,
在数据库中,我有静态表 Report 和 EAV 表,它们帮助我存储报表的 ReportProperty。
在域模型中,我想要这样的报告:

Report
{
     ICollection<ReportProperty> ReportProperties{get;set;}
}

我可以使用由实体框架和部分部分生成的报告实体 在 getter 中实现一些逻辑,用于从我的 EAV 表中检索数据以填充 Collection ReportProperies。然后它引出了下一个问题。

  1. 如果我决定使用 NHibernate 而不是实体框架,因为我无法使用我已经使用实体框架实现的部分部分,我该怎么办?

如果我将使用 DDD 对象(我可以将其用于实体框架或 NHibernate),那么这对我来说将很难,因为我将需要在 DAO 中的每个过程中调用映射过程。

Some tables in my database is designed using EAV concept.
Then I use entities which are auto generated and represent "static" tables (not "EAV" tables) by ORM Entity Framework as DDD objects.

  1. How can I use my "EAV" entities in object model (not in relational like in database) using Entity Framework?

For example,
in the database I have static table Report and EAV tables which help me store ReportProperty for Report.
In domain model I want have Report like that:

Report
{
     ICollection<ReportProperty> ReportProperties{get;set;}
}

I can use Report entity which is generated by Entity Framework and in partial section
realise some logic in getter for retrieving data from my EAV tables to fill Collection ReportProperies. Then it begs the next question.

  1. What can I do if I decide use NHibernate instead Entity Framework, because i can`t use my partial section which i already realize using Entity Framework?

If I will be use DDD objects, which i can use for Entity Framework or NHibernate, it will be hardly for me, because I will need call mapping procedures in each procedures in my DAO.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别低头,皇冠会掉 2024-10-15 21:11:16

EAV是数据访问层的概念,而DDD是业务逻辑层的概念。像 Entity Framework 或 NHibernate 这样的 ORM 诱使我们将这两个层混合在一起,但在具有复杂逻辑的复杂项目中(这就是需要 DDD 的地方),这种情况永远不应该发生。所以把你的 Dal 和 Bll 分开。对 DDD 对象使用手工制作的类,对实体框架使用自动生成(或代码优先)的类,并在它们之间提供映射层。那么 EAV 将只是 Dal 的一个实现细节。如果您切换到 NHibernate,您的 Bll 和 DDD 类也不必更改。只需您的映射层即可。顺便说一句,使用依赖倒置。让你的达尔依赖于你,而不是相反。如果您使映射层在物理上与实体框架部件分离,则在程序集级别上使用中介模式(意味着您的映射层取决于您的 Bll 和 Dal,而不是任何其他方式)。

EAV is a concept of the data access layer, while DDD is a concept of the business logic layer. ORM like Entity Framework or NHibernate tempt us to mix this both layers, but in complex projects with complex logic (that is where DDD is needed) this should never happen. So divide your Dal and Bll. Use hand crafted classes for you DDD objects and use auto generated (or code first) classes for Entity Framework and provide a mapping layer between them. Then EAV will be just an implementation detail of your Dal. Also your Bll and DDD classes wil not have to change, if you switch to NHibernate. Just your mapping Layer would. And by the way, use Dependency Inversion. Make your Dal depend on you Bll and not the other way around. If you make the mapping layer physically separate from your Entity Framework parts, then use mediator pattern on assembly level (meaning your mapping layer depends on your Bll and your Dal and not any other way around).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文