使用没有 ORM 的 SQL 的规范模式,以及存储库模式
我一直在研究 martin fowler 的企业架构模式中存储库模式部分简要描述的规范模式,以及网络上的几个示例。然而,几乎所有的示例/描述都是通过利用 ORM 和 IsSatisfiedBy 等方法创建的,这些方法由规范对象执行(并且可能由 ORM 转换为 SQL)。
我可以看到如何调整它以与 SQL 一起使用,但由于普遍缺乏 SQL 示例,我想知道人们是否将此模式与 SQL 数据访问层和存储库模式一起使用,以及他们的经验/方法如果是的话,或者可能更适合该任务的任何替代方案(如果有)。
I have been looking into the specification pattern that is briefly described in martin fowler's patterns of enterprise architecture under the repository pattern section, as well as several examples on the web. However, almost all of the examples/descriptions are created by utilizing an ORM and methods such as IsSatisfiedBy which are executed by the specification objects(and probably converted into SQL by the ORM).
I can see how you might adapt it to work with SQL, but due to a general lack of SQL examples, I was wondering if people are using this pattern with a SQL data access layer and the repository pattern, and their experience/approach with it if they are, or any alternatives that may be better suited to the task if there are any.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用清洁架构,您有以下限制:
因此,您需要
如果您没有使用 ORM,则使规范模式发挥作用所缺少的部分是从规范和域实体到 SQL 和数据库表的映射。
实体框架根据任一约定开箱即用地执行此操作、属性或 Fluent API。
您可以
不幸的是,我还没有进一步探索这些选项。
With Clean Architecture, you have these restrictions:
Therefore, you need to write your specifications
If you are not using an ORM, the missing piece to making Specification Pattern work is the mapping from specifications and domain entities to SQL and database tables.
Entity Framework does this out of the box, based on either conventions, attributes or the Fluent API.
You can either
Unfortunately, I haven't explored these options further yet.
我相信 LINQ 有效地实现了规范模式的需求
(我相信这也与您使用 SQL 的请求有关)。
我怀疑还有 API 可以在没有 LINQ 解析树的情况下输出 SQL。
因此,实体框架或 LINQ to SQL 值得研究。
我希望这能回答你的问题。
I believe that LINQ effectively implements the need to the specification pattern
(I believe that this also ties into you request to work with SQL).
I suspect there are also APIs to spit out SQL without LINQ parse trees.
So, Entity Framework or LINQ to SQL would be worth looking into.
I hope this answers your question.