CodeSmith 自动生成NHibernate

一、官网可以下载最新版http://www.codesmithtools.com/

       但是需要注册码,所以国内网站上搜下有破解版的。目前我下载的是6.5版本和注册机的(或者用使用key一个月的免费期)

       1、先安装codesmith 6.5装完以后运行破解安装工具。

       2、下载模版https://www.codesmithtools.com/product/generator#templates ,把nhibernate的模版下下来。

       这里其实可以不下载nhibernate的模版因为,codesmith已经自带了,只不过名字改了:PLINQO-NH。下面一个模板是下载的模版通过解压后从左上角的文件夹图标添加进来的随便用哪个都可以。

 

   

二(1)、点击QuickStart.cst  ,开始配置数据源等 新建一个工程。

       1、双击图标或者右击点击execute 都可以弹出配置:数据源需要自己配一下

      

        2、连接字符串需要自己写,但是不会写的可以点旁边的省略号,不知道我的什么情况,旁边的省略号都没有,幸亏前面弄MyGeneration的时候也碰到过这个类似的问题,直接拷过来用了(官网先下载个connection/net6.6.5原因同vs2010只有sqlserver的连接器如果需要在vs2010连接数据库查看也必须安装我已经安装了这里不用安装了)

Database=edu;Data Source=localhost;UserId=root;Password=;

以上还可以修改其他的配置,比如解决方案名称,项目名称,输出目录等然后直接点击generate就好了。

      3、成功以后用vs2010打开点击里面的自动生成文件,execute->直接点击generate,vs2010会自动加载创建的文件。

      虽然创建成功了,但是离我想要的相差太远,这个模板好像又封装了一层generated.cs。还是用动软吧。。。

二(2)、 添加已有的解决方案下面去,直接拷贝不写了。

              只需注意几个地方,这里需要用到下载的nhibernate模版,因为下面有需要添加模版文件生成。

             建好了直接添加进类库工程就可以了

Manual Configuration

 

Add PLINQO to a pre-existing project.

Step 1: Open a Visual Studio Project

Either create a new project, or open the project that you want to add your NHibernate files to.

Step 2: Add a new CodeSmith Project (CSP) to your project.

  1. Open your project in Visual Studio.
  2. Right click on your project in Solution Explorer and add a "New Item"
  3. Under "Visual Studio C# Items", and add a "Generator Project"

Step 3: Configurate your CSP for PLINQO for NHibernate

  1. Right click on the CSP and "Manage Outputs"
  2. Add Output, select Hbms.cst, and fill in the 2 required properties
  3. Add Output, select Entities.cst, and fill in the 2 required properties
  4. Add Output, select Queries.cst, and fill in the 1 required property

 

Step 4: Add a connection string to your App or Web config

  1. Name the connection string "nhiberante" or the name of your database

Step 5: Generate Outputs

  1. Right click on your CSP and Generate Outputs.
  2. Compile.
  3. Enjoy!

转载地址:http://blog.csdn.net/fax5201314/article/details/8626680

posted @ 2015-01-31 12:53  一生有你.Net  阅读(1166)  评论(0)    收藏  举报