从数据库模式生成类

发布于 2024-08-02 03:36:58 字数 384 浏览 3 评论 0原文

我仔细研究了以前提出的问题,但没有找到重复的问题。 我希望从 DB2 模式(使用 iSeries OLEDB 提供程序)在 .Net 中生成基本实体类。 有什么简单的方法可以做到这一点吗? 我研究了 MyGeneration 和 CodeSmith,似乎必须有一种更简单的方法。

提前致谢。

编辑 我去掉了 iSeries 标签,希望它能稍微缓解这个问题。 有人拥有针对任何 ADO.Net 或 OLEDB 提供商的任何东西吗? 我想我可以调整它以与 iSeries 一起使用。

编辑#2重新添加 iSeries 标签并将在几天内接受我自己的答案,希望这对将来的人有所帮助。 给回复者+1,谢谢。

I've dug around through previously asked questions and have had no luck finding a duplicate. I would love to generate basic entity classes in .Net from a DB2 schema (using the iSeries OLEDB provider). Is there any simple way to do this? I've looked into MyGeneration and CodeSmith and it just seems like there must be an easier way.

Thanks in advance.

EDIT
I'm taking the iSeries tag off of this in hopes that it will de-scarify the question a bit. Anyone have anything that they've used against any ADO.Net or OLEDB provider? I think I could adapt it to work with iSeries.

EDIT #2 Adding the iSeries tag back on and will accept my own answer in a couple of days, hopefully this will help someone in the future. +1 to responders, thanks.

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

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

发布评论

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

评论(3

美羊羊 2024-08-09 03:36:58

你试过吉夫斯吗? 它是一个用 Perl 编写的模板驱动的代码生成器。

使用 Jeeves,您可以分别修改规范解析器和模板,并将 Perl 命令注入模板中。

我没有完全按照你想要的方式去做,但我做了以下事情:

1)使用 Jeeves 的分布式 OO 解析器,并在规范文件中创建我的对象定义,该文件的格式是该解析器可以使用的读。
2) 我对模板进行了编码,以使用 OO 解析器从我的规范文件生成的抽象语法树。
3) 这又会生成一个 Perl 代码生成器。 我将此代码生成器称为 pre-buld 事件(在 VS 2005 中),生成的代码立即被编译。

您必须构建您想要的模板(可能还有规范解析器),但是一旦您这样做了,您就可以准确地输出您想要的内容,而无需大量额外的开销。

Have you tried Jeeves? It's a template-driven code generator written in Perl.

With Jeeves you can modify the specification parser and the templates separately, and inject Perl commands into the template.

I didn't do exactly what you want to do, but what I did was the following:

1) Used Jeeves' as-distributed OO parser, and created my object definitions in a specification file, which is in a format that this parser could read.
2) I coded the template to consume the abstract syntax tree that the OO parser generated from my specification file.
3) This in turn generates a code generator in Perl. I called this code generator as a pre-buld event (in VS 2005) and the generated code was compiled right then and there.

You'll have to build the template you want (and probably the spec parser) but once you do that you can output exactly what you want without a lot of extra overhead.

江南月 2024-08-09 03:36:58

这可能有点啰嗦,但一种方法是使用 将架构逆向工程为对象角色建模图NORMA VS 插件,然后通过插件附带的 PLiX 生成器生成 .NET 类。

您可能会发现生成的类用您可能不需要的额外成员进行修饰(它们经过编码,以便可以在如果需要,可以在组件模型上下文中使用),但您可以轻松地去除这些额外的工件。

This is perhaps a little long winded, but one way is to reverse engineer the schema into an Object Role Modelling diagram using the NORMA VS plug in and then generate your .NET classes via the PLiX generator which comes with the plug in.

You may find the resulting classes are decorated with extra members which you may not need (they are coded so they can be used in a component model context if required) but you can strip these extra artefacts easily enough.

终陌 2024-08-09 03:36:58

经过更多研究,我决定自己编写代码生成器。 我问这个问题的部分原因是因为 .Net 的 iSeries 提供程序不是很强大,因此没有给定的方法来枚举架构信息。 但是,在找到这个问题后,我能够使用像这样的简单内联 SQL:

//Enumerate schema tables (excludes views)
select table_name from qsys2.tables where table_schema = 'schema_name' and table_type = 'BASE TABLE'

//Enumerate table columns
select * from qsys2.columns where table_schema = 'schema_name' and table_name = 'table_name' order by ordinal_position;

也许这会对将来的某人有所帮助。

After more research, I decided to write the code generator myself. Part of the reason I asked was because the iSeries provider for .Net isn't very robust, so there's no given way to enumerate schema information. However, after finding this question, I was able to do it using simple inline SQL like this:

//Enumerate schema tables (excludes views)
select table_name from qsys2.tables where table_schema = 'schema_name' and table_type = 'BASE TABLE'

//Enumerate table columns
select * from qsys2.columns where table_schema = 'schema_name' and table_name = 'table_name' order by ordinal_position;

Maybe this will help someone in the future.

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