关于CQRS的查询端
我相信将查询端与命令端分离的优点。对于查询端,我们可以以最优化的形式为客户端提供所需的信息;这使得它变得快速而简单。就我而言,我使用查询端的一种非常简单的实现,这基本上意味着我想使用与命令端使用的数据库相同的数据库。
我的问题是如何实现查询端,这就是我的想法:
1/ 我的第一个想法是使用 WCF 数据服务,基于在数据库视图上生成的实体框架模型。然后我会为特定的 UI 创建特定的视图。然后,一个视图可以合并来自不同表的数据。但这似乎非常有限,因为您无法将参数传递给视图,并且对于大多数查询我当然需要传递参数。
2/ WCF 数据服务,基于在数据库表上生成的实体框架模型。但是,查询模型将与命令端使用的模型相同。并且您无法以最适合特定 UI 的方式获取信息。
3/ WCF 数据服务,基于在数据库存储过程上生成的实体框架模型。但接下来还有额外的工作来揭露它们;并且调用它们也有点奇怪(魔术字符串)。
为了帮助我做出决定,我很想听听您的意见,看看什么是暴露我的查询方面的最佳方式。谢谢!
I believe in the advantages of separating the query side from the command side. For the query side, we can provide the needed information in the most optimized form for the client; which makes it fast and easy. In my case, I use a very simple implementation of the query side, which basically means I want to to use the same database as the one used for the command side.
My question is about how I can implement the query side, and this is what I was thinking:
1/ My first thought was to use a WCF data service, based on an entity framework model that is generated on database views. I would then create specific views for specific UI's. One view can then merge data from various tables. But this seems very limited, because you can't pass parameters to views, and for most queries I need to pass parameters of course.
2/ A WCF data service, based on an entity framework model that is generated on database tables. But then, the query model would be the same as the one used for the command side. And you don't get back the information in the way that is best suitable for the specific UI.
3/ A WCF data service, based on an entity framework model that is generated on database stored procedures. But then there's extra work to expose them; and calling them is also a bit strange (magic strings).
In order to help me to make a decision, I would love to hear your comments to see what would be the best way of exposing my query side. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会选择选项 1。为您的应用程序将要进行的特定查询创建完全非规范化的视图。
当您说无法将参数传递给视图时,您的意思是什么?为什么不能对视图运行常规查询?
I'd go with option 1. Create fully de-normalised views for the specific queries your application will be making.
When you say you can't pass parameters to views what do you mean? Why can't you run a regular query against the views?