用于ORM映射的代码生成工具

时间:2022-10-20 19:32:02

There seems to be no end of code generation tools out there and would rather not have to go through each to see what is still maintained, easy to use, and provides customization. The code generation is for NHibernate mapping and subsequent creation of value objects or Data Transfer objects (DTO). It would be great if it could also generate in other languages such as action script.

似乎没有代码生成工具的结束,而是不必通过每个工具来查看仍然维护,易于使用和提供自定义的内容。代码生成用于NHibernate映射以及随后创建的值对象或数据传输对象(DTO)。如果它也可以用动作脚本等其他语言生成,那就太好了。

As this app being developed is using the database the ORM is generally a 1:1 mapping. I know that this defeats most of reasons of using NHibernate but that is what it is.

由于正在开发的这个应用程序正在使用数据库,因此ORM通常是1:1映射。我知道这会破坏使用NHibernate的大部分原因,但事实就是如此。

4 个解决方案

#1


T4 -- built into Visual Studio 2008. You've already got it for free. Works well, fully supported. If you do some searching you can find T4 scripts for Linq To Sql, and Entity Framework. I'm sure an NHibernate script exists as well.

T4 - 内置于Visual Studio 2008中。您已经免费获得它。效果很好,完全支持。如果您进行一些搜索,可以找到Linq To Sql和Entity Framework的T4脚本。我确信NHibernate脚本也存在。

MyGeneration: Open Source, also very good. No Visual Studio integration.

MyGeneration:开源,也很好。没有Visual Studio集成。

Code Smith: Commercial, does the job very well. Also integrates into Visual Studio.

Code Smith:商业,做得很好。还集成到Visual Studio中。

All of them are customizable. Code Smith and T4 are both very similar to me as far as the script goes.

所有这些都是可定制的。就剧本而言,Code Smith和T4与我非常相似。

#2


I generally create an XSLT which queries sysobjects joined to syscolumns (assumes one is using SQL Server) and transform the output to build the necessary structures. This has the downside that you have to code and debug it yourself. However, once you've got it working, you have 100% flexibility to extend and customize it and the only cost is for time and effort upfront (usually about 2-3 days to get an initial working copy).

我通常创建一个XSLT来查询连接到syscolumns的sysobjects(假设一个是使用SQL Server)并转换输出以构建必要的结构。这有一个缺点,你必须自己编码和调试它。但是,一旦您使用它,您就可以100%灵活地扩展和定制它,而且前期的时间和精力是唯一的成本(通常大约需要2-3天才能获得初始工作副本)。

Hope this helps,

希望这可以帮助,

Bill

#3


I haven't had time to look at it yet, but Entity Framework in 4.0 (VS2010, now available in public beta) supports T4 templates for code generation from edmx... so you can customize it pretty much as you like. Search for "Entity Framework T4 Template" and you'll find a lot, especially from the last few days.

我还没来得及查看它,但4.0中的实体框架(VS2010,现在可在公共测试版中使用)支持从edmx生成代码的T4模板...因此您可以根据自己的喜好自定义它。搜索“实体框架T4模板”,你会发现很多,特别是从最近几天。

#4


We've used open source NVelocity

我们使用了开源NVelocity

#1


T4 -- built into Visual Studio 2008. You've already got it for free. Works well, fully supported. If you do some searching you can find T4 scripts for Linq To Sql, and Entity Framework. I'm sure an NHibernate script exists as well.

T4 - 内置于Visual Studio 2008中。您已经免费获得它。效果很好,完全支持。如果您进行一些搜索,可以找到Linq To Sql和Entity Framework的T4脚本。我确信NHibernate脚本也存在。

MyGeneration: Open Source, also very good. No Visual Studio integration.

MyGeneration:开源,也很好。没有Visual Studio集成。

Code Smith: Commercial, does the job very well. Also integrates into Visual Studio.

Code Smith:商业,做得很好。还集成到Visual Studio中。

All of them are customizable. Code Smith and T4 are both very similar to me as far as the script goes.

所有这些都是可定制的。就剧本而言,Code Smith和T4与我非常相似。

#2


I generally create an XSLT which queries sysobjects joined to syscolumns (assumes one is using SQL Server) and transform the output to build the necessary structures. This has the downside that you have to code and debug it yourself. However, once you've got it working, you have 100% flexibility to extend and customize it and the only cost is for time and effort upfront (usually about 2-3 days to get an initial working copy).

我通常创建一个XSLT来查询连接到syscolumns的sysobjects(假设一个是使用SQL Server)并转换输出以构建必要的结构。这有一个缺点,你必须自己编码和调试它。但是,一旦您使用它,您就可以100%灵活地扩展和定制它,而且前期的时间和精力是唯一的成本(通常大约需要2-3天才能获得初始工作副本)。

Hope this helps,

希望这可以帮助,

Bill

#3


I haven't had time to look at it yet, but Entity Framework in 4.0 (VS2010, now available in public beta) supports T4 templates for code generation from edmx... so you can customize it pretty much as you like. Search for "Entity Framework T4 Template" and you'll find a lot, especially from the last few days.

我还没来得及查看它,但4.0中的实体框架(VS2010,现在可在公共测试版中使用)支持从edmx生成代码的T4模板...因此您可以根据自己的喜好自定义它。搜索“实体框架T4模板”,你会发现很多,特别是从最近几天。

#4


We've used open source NVelocity

我们使用了开源NVelocity