生成简单的只读 DAL?

发布于 2024-09-04 11:41:32 字数 1036 浏览 0 评论 0原文

我一直在寻找一个简单的解决方案来解决这个问题,尽我最大的努力倾向于NHibernate之类的东西,但到目前为止我发现的所有东西似乎都在试图解决一个稍微不同的问题。以下是我在当前项目中关注的内容:

我们有一个 IBM iSeries 数据库,作为用于我们核心业务(金融机构)的第三方软件套件的主要存储库。我的团队所做的一部分工作是编写应用程序,以某种方式报告或关闭大量此类数据。过去,我们一直手动创建 ADO .NET 连接(顺便说一下,我们使用的是 .NET 3.5 和 Visual Studio 2008)并手动编写查询等。

展望未来,我想简化以下过程:为开发团队从那里获取数据。我更希望开发人员能够简单地执行以下操作,而不是每次都创建连接和查询之类的操作:

var something = (from t in TableName select t);

而且,理想情况下,他们只需获取生成实体的一些 IQueryable 或 IEnumerable 即可。这将在我正在构建的新域核心内完成,这些实体将驻留在该域核心中,并且应用程序将通过请求/响应服务层与其进行交互。

需要注意的一些事情是:

  1. 与数据库表相对应的实体应该生成一次,并且我们更愿意随着时间的推移手动更新它们。也就是说,如果将列/表添加到数据库中,那么我们不必执行任何操作。 (当然,如果删除了一些,它会损坏,但这没关系。)但是如果我们需要使用新列,我们应该能够将其添加到必要的类中,而无需重新生成整个事情。
  2. 整个事情应该是仅限 SELECT 的。我们在这里没有执行完整的 DAL,因为我们不希望能够破坏数据库中的任何内容(即使是意外)。
  3. 我们不需要域对象和生成的实体类型之间的任何类型的映射。该域几乎覆盖了其中的一小部分数据,其中大部分我们永远不需要,而且我们宁愿随着时间的推移手动创建可重复使用的地图。我已经对 DAL 进行了逻辑分离,其中我的“存储库”类返回域对象,我只是在寻找在存储库类中使用的手动 ADO 的更好替代方案。

有什么建议吗?看起来我正在做的事情超出了对 DAL/ORM 工具/在线教程的正常需求,我还没有找到任何东西。或者也许我只是忽略了一些显而易见的事情?

I've been looking around for a simple solution to this, trying my best to lean towards something like NHibernate, but so far everything I've found seems to be trying to solve a slightly different problem. Here's what I'm looking at in my current project:

We have an IBM iSeries database as a primary repository for a third party software suite used for our core business (a financial institution). Part of what my team does is write applications that report on or key off of a lot of this data in some way. In the past, we've been manually creating ADO .NET connections (we're using .NET 3.5 and Visual Studio 2008, by the way) and manually writing queries, etc.

Moving forward, I'd like to simplify the process of getting data from there for the development team. Rather than creating connections and queries and all that each time, I'd much rather a developer be able to simply do something like this:

var something = (from t in TableName select t);

And, ideally, they'd just get some IQueryable or IEnumerable of generated entities. This would be done inside a new domain core that I'm building where these entities would live and the applications would interface with it through a request/response service layer.

A few things to note are:

  1. The entities that correspond to the database tables should be generated once and we'd prefer to manually keep them updated over time. That is, if columns/tables are added to the database then we shouldn't have to do anything. (If some are deleted, of course, it will break, but that's fine.) But if we need to use a new column, we should be able to just add it to the necessary class(es) without having to re-gen the whole thing.
  2. The whole thing should be SELECT-only. We're not doing a full DAL here because we don't want to be able to break anything in the database (even accidentally).
  3. We don't need any kind of mapping between our domain objects and the generated entity types. The domain barely covers a fraction of the data that's in there, most of it we'll never need, and we would rather just create re-usable maps manually over time. I already have a logical separation for the DAL where my "repository" classes return domain objects, I'm just looking for a better alternative to manual ADO to be used inside the repository classes.

Any suggestions? It seems like what I'm doing is just enough outside the normal demand for DAL/ORM tools/tutorials online that I haven't been able to find anything. Or maybe I'm just overlooking something obvious?

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

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

发布评论

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

评论(2

故事灯 2024-09-11 11:41:32

您可能想调查一下:

http://www.codesmithtools.com/

我一直在使用这个工具的项目很少,而且开发人员很喜欢它。

警告:它不是免费软件。

You might want to investigate this:

http://www.codesmithtools.com/

I've been on a few projects where this tool was used, and the developers were fond of it.

Warning: it's not freeware.

一指流沙 2024-09-11 11:41:32

添加到 code4life 的答案。

我最近在家里的一个宠物项目中使用了 CodeSmith 2.6。
我定制了模板来生成具有部分 CRUD 方法的部分类。
然后,我扩展了部分类和部分方法以提供基本映射,例如,当读取“Order”时,读取关联的“OrderLines”等。

类似的方法可能对您有用,并且更简单,因为实际上,您只需要 CRUD 的 R :)

希望这有帮助。

PS 我需要从 CS 2.6 切换到其他版本(可能是 MyGeneration),因为 2.6 依赖于 .Net 1.1,这是一个问题,因为我正在转向 64 开发机器。

更新

我听到了。
好好看看 MyGeneration 伙伴,我们在工作中使用 CodeSmith,这就是为什么我在家里选择 2.6(我快速浏览了 MyGeneration,并没有立即得到它 - 这比我需要付出的时间要多)它 - 所以切换回CS)。

MyGeneration 基本上是 CS 的开源版本。

另外,为什么不让它总是生成代码 - 您可以使用部分类和部分类来调整您的心内容。部分方法,我知道您认为重新生成太过分了,但经验告诉我,这是一种如果您没有它就会需要它的东西,就好像您拥有它并且需要它你永远不会注意到。

Adding to code4life's answer.

I recently used CodeSmith 2.6 on a pet project at home.
I tailored the templates to generate Partial classes with partial CRUD methods.
I then extended the partial classes and partial methods to provide basic mapping e.g. when "Order" is read, read the associated "OrderLines" etc.

A similar approach might work for you, and be simpler because really, you only want the R of CRUD :)

Hope this helps.

P.S. I need to switch from CS 2.6 to something else (possibly MyGeneration), as 2.6 is dependant on .Net 1.1, which is a problem as I'm moving to a 64 development machine.

UPDATE

I hear ya.
Have a good poke a MyGeneration mate, we use CodeSmith here in work, which is why I went for 2.6 at home (I'd a quick glance at MyGeneration, didn't get it immediately - which was more time than I had to give it - so switched back to CS).

MyGeneration is basically an open source version of CS.

Also, why not get it to generate the code ALWAYS - you can tweak to your hearts content with Partial Classes & Partial Methods, I know you think re-generating is overkill, but experience tells me it's one of those things that if you don't it have you'll need it, where as if you have it and need it you'll never notice.

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