昨晚,我在设计新项目时遇到了一些有趣的事情,这让我在这里问这个问题。
我的项目应该遵循表网关模式,使用传统的 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 ?
发布评论
评论(2)
您正在描述一个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.
您可能想查看 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.