只读数据库视图如何适应存储库模式? [英] How do read-only database views fit into the repository pattern?
问题描述
示例:您的数据库具有一个名为 CustomerOrdersOnHold的SQL视图。该视图返回特定客户和订单数据字段的混合过滤。您需要从应用程序中的此视图中获取数据。对这种视图的访问如何适应存储库模式?您将创建 CustomerOrdersOnHoldRepository吗?这样的只读视图是否被认为是聚集根?
Example: Your database has a SQL view named "CustomerOrdersOnHold". This view returns a filtered mix of specific customer and order data fields. You need to fetch data from this view in your application. How does access to such a view fit into the repository pattern? Would you create a "CustomerOrdersOnHoldRepository"? Is a read-only view such as this considered an aggregate root?
推荐答案
我宁愿分离读取存储库,最好甚至更改它的名称为Finder或Reader,该存储库仅用于域使用,而不用于查询只读数据,您可以参考本文和此,它解释了Finder分隔表格存储库的用法。
I would prefer separating the read repository, preferably even change its name to Finder or Reader, the repository is meant for Domain usage not for querying read-only data, you can refer to this article and this which explains the usage of Finder separated form repository.
I would recommend also the separating of read model from write model architecture CQRS and there
此架构允许您甚至可以在数据存储和事件源的使用方面将读取模型与写入模型分开。
This architecture allows you to separate the read model from write model even in terms of data storage and the use of event sourcing.
对于中间解决方案,您可以利用一些CQRS概念而无需复杂性通过仅将存储库与查找器分离来分离数据库的方法,请阅读此发布
For a middle solution you can utilize some CQRS concepts without the complexity of separating database by just separating repository from finders, read this post
获取此类解决方案的示例(使用相同的数据库,但将查找者从表单存储库中分离出来)check < a href = http://sellandbuy.codeplex.com/ rel = nofollow noreferrer>此示例
for a sample of this type of solution (use the same database but separating finders form repositories) check this sample
这篇关于只读数据库视图如何适应存储库模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!