编写类型化 SQL 语句 API 的设计指南?

发布于 2024-08-28 00:13:11 字数 277 浏览 5 评论 0 原文

昨晚,我在设计新项目时遇到了一些有趣的事情,这让我在这里问这个问题。

我的项目应该遵循表网关模式,使用传统的 ADO.Net 数据集进行数据访问。我不想在数据访问类中编写简单的查询。因此,我想到了编写一个解析器 api,它公开对象和方法,以根据我的域对象生成移动查询。

稍后,我希望此 api 连接到我的业务对象,并在业务对象实例上提供类型化 SQL 生成器 api。

有什么想法或参考资料我该如何做到这一点?一开始这似乎很广泛,我不得不在这里听取你的意见。是否已经存在可以做到这一点的东西?

Last night I came up to sometihng intersting while designing my new project that brought me to ask this qustion here.

My project is supposed to follow Table Gateway pattern using tradional ADO.Net datasets for data access. I don't want to write plain queries in my data-access classes. So I came up with an idea of writing a parser kindaa api that exposes objects and methods to generate queries on the move based on my domain objects.

Later I want this api to hook up to my Business objects and provide Typed SQL generator api right on the business object instances.

Any idea or references how can I do this ? This seems very wide to start with that I'm compelled take your opinions here. Does there anything already exists that can do this ?

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

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

发布评论

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

评论(2

时常饿 2024-09-04 00:13:11

您正在描述一个ORM(对象关系映射器)。周围有很多这样的工具,nHibernate 可能是 .网络圈子。

有很多不同的 ORM,我建议您在开始编写自己的 ORM 之前先看看这些。如果您确实需要,可以通过 Davi Brion 关于构建您自己的数据层,他在其中构建了一个简单的 ORM。

You are describing an ORM (Object Relational Mapper). There are many of those around, nHibernate is probably one of the better known and used in the .NET circles.

There are many many different ORMs, and I would suggest you look at those before you start writing your own. If you really must, you can follow this set of blog posts by Davi Brion about building your own data layer, where he builds up a simple ORM.

瀞厅☆埖开 2024-09-04 00:13:11

您可能想查看 ADO.NET 实体框架 - 这将您的数据公开为强类型业务对象,并允许您使用强类型表达式或 Linq 查询构建查询。

You might want to take a look at the ADO.NET Entity Framework - this exposes your data as strongly typed business objects, and allows you to build queries using strongly typed expressions or Linq queries.

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