存储库、实体对象和域对象

发布于 2024-07-15 02:26:26 字数 201 浏览 4 评论 0原文

在我的存储库中,我从 Linq 实体查询对域对象进行分配。 然后,我有一个服务层来处理从存储库返回的这些对象。

我的域对象应该像这样位于存储库中吗? 或者我的存储库应该仅限于实体和数据访问,而让我的服务层对域对象进行分配?

在存储库中完成所有分配似乎更容易,但现在我的数据库和域对象之间的区别并不明显。 这里什么是正确的做法? 蒂亚

In my Repositories, I am making assignments to my domain objects from the Linq Entity queries. I then have a service layer to act on these object returned from repositories.

Should my Domain objects be in the repository like this? Or should my repositories be restricted to the Entities and Data Access, and instead have my service layer make assignments to the domain objects?

Doing all assignments in Repository seems easier, but now the distinction between my database and domain objects is not apparent. What is proper practice here? tia

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

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

发布评论

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

评论(2

三生一梦 2024-07-22 02:26:26

IMO,如果应用程序相对简单,并且您无法想象取消数据访问,请继续在存储库中进行分配。 但是,如果您认为应用程序将来会变得更加复杂,或者您可能想要更改数据访问权限,请将此功能保留在存储库之外。

我已经完成了在存储库和服务层中进行分配的应用程序,而另一个应用程序我有一个单独的转换层(它不是一对一的转换,并且对象很复杂)。

关于最佳实践需要记住的一件事是,它可以提供帮助,如果它使事情变得更加困难,那么就不要使用它。

IMO if the app is relativly simple and you cant imagine ripping out the Data access go ahead and make the asignments in the Repository. But if you think the app will get more complicated in the future or that you may want to change the data access keep this functionality out of the repositories.

I have done apps with assignement in the repositories and other in the service layer and yet another one i had a seperate conversion layer (it was not a one on one conversion and the objects were complex).

One thing to remember about best practices, There there to help, if it makes thing more dificult then dont use it.

心不设防 2024-07-22 02:26:26

我以前不喜欢它。 但现在通常不会回头。 基本上,如果您需要更改为结构不同的外部数据源,您可以设置一个新的映射以及存储库代码的实现并完成它。

这是关于数据映射的。 检查此链接:http://www.martinfowler.com/eaaCatalog/repository.html

另请检查此相关问题:IRepository 对返回对象的混淆。 我使用了类似的映射器,但使其在 IQueryable 级别上运行,这使得在映射后处理域对象时能够做一些非常有趣的事情。

I used to not like it. But now usually never look back. Basically the thing is that if you need to change to an external datasource that is structured different, you can set up a new mapping along with the implementation of the repository code and be done with it.

It is about data mapping. Check this link: http://www.martinfowler.com/eaaCatalog/repository.html

Also check this related question: IRepository confusion on objects returned. I have used a similar mapper, but have made it operated at the IQueryable level, which have made able to do some pretty interesting stuff while working with the Domain Object after the mapping.

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