USING NHIBERNATE WITH MySQL
In previous USING NHIBERNATE WITH SQLITE, we connect SQLITE with ORM framework NHibernate. One of the biggest advantage of ORM is that most code need not be changed when switching different DBMS. In this article, MySQL is used for DBMS.
For the switching, hibernate.cfg.xml and default.build have to be updated.
1. hibernate.cfg.xml
Update the driver and connection string.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Server=localhost;Database=test;User ID=root;Password=</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="query.substitutions">true=1;false=0</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
2. default.xml
Update assembly dependencies.
<?xml version="1.0"?>
<project name="SQLite with NHibernate" default="run">
<property name="debug" value="true" />
<property name="outdir" value="bin" />
<property name="libdir" value="../lib" />
<property name="mysql_libdir" value="../../MySQL/lib/v4.0" />
<target name="clean" description="remove all generated files">
<delete dir="${outdir}" />
</target>
<target name="build" description="compiles the source code">
<mkdir dir="${outdir}" />
<csc debug="${debug}" output="${outdir}/NHExample.exe" target="exe">
<references basedir="${libdir}">
<include name="NHibernate.dll" />
</references>
<sources>
<include name="Domain/Product.cs" />
<include name="NHExample.cs" />
</sources>
<resources dynamicprefix="true" prefix="NHExample.Domain">
<include name="Mappings/*.hbm.xml" />
</resources>
</csc>
<copy todir="${outdir}">
<fileset basedir="${libdir}">
<include name="NHibernate.dll" />
<include name="NHibernate.xml" />
<include name="Iesi.Collections.dll" />
<include name="Iesi.Collections.xml" />
</fileset>
</copy>
<copy todir="${outdir}">
<fileset basedir="etc">
<include name="hibernate.cfg.xml" />
</fileset>
</copy>
<copy todir="${outdir}">
<fileset basedir="${mysql_libdir}">
<include name="mysql.data.dll" />
<include name="mysql.data.entity.dll" />
</fileset>
</copy>
</target>
<target name="run" depends="build">
<exec program="${outdir}/NHExample.exe" workingdir="${outdir}"/>
</target>
</project>
执行的输出结果:

Done. We have make the DBMS switching without coding and changing mappings.
USING NHIBERNATE WITH MySQL的更多相关文章
- 【C#】使用NHibernate连接MySQL数据库及增删改查
学习资料 http://www.sikiedu.com/course/51/task/891/show https://www.codeproject.com/Articles/26123/NHibe ...
- 使用NHibernate连接MySQL数据库及增删改查
学习资料 http://www.sikiedu.com/course/51/task/891/show https://www.codeproject.com/Articles/26123/NHibe ...
- 利用NHibernate与MySQL数据库交互
本文章使用Visual Studio作为开发工具,并建立在已经安装MySQL数据库的前提. NHibernate是一个面向.NET环境的对象/关系数据库映射工具.官网:http://nhibernat ...
- Fluent NHibernate and Mysql,SQLite,PostgreSQL
http://codeofrob.com/entries/sqlite-csharp-and-nhibernate.html https://code.google.com/archive/p/csh ...
- MySql(一)_利用NHibernate和MySql交互
1.基础配置,添加MySql和nHibernate的引用 (1) 添加引用,导入MySql.data.dll: 利用MySql提供的API操作: (2) 添加引用,导入NHibernate.d ...
- NHibernate+MySql (erro 解决方法)
error1. Could not create the driver from NHibernate.Driver.MySqlDataDriver 解决方法:在使用Nhibernate连接Mysq ...
- [NHibernate] 入门实例 NHibernate 3.3 GA + VS2010 +MySQL
题外话: 中国的技术论坛要赶上stackoverflow的水平.至少还需35年.中国程序猿笔者的特点是:太浮躁,太easy下总结.太自得其乐,虽说写的是为了让别人更好的看.却也演变成了一种" ...
- 【NHibernate】列“ReservedWord”不属于表 ReservedWords
NHibernate+FluentNHibernate+MySql 运行时黄页显示下边的异常,项目中找了半天没出现过这个列的关键字. [ArgumentException: 列“ReservedWor ...
- 架构之路(九)Session Per Request
前面的两篇反应很差:没评论没赞.很伤心啊,为什么呢?搞得我好长一段时间都没更新了——呵呵,好吧,我承认,这只是我的借口.不过,还是希望大家多给反馈.没有反馈,我就只能猜了:前面两篇是不是写得太“粗”了 ...
随机推荐
- 1643【例 3】Fibonacci 前 n 项和
1643:[例 3]Fibonacci 前 n 项和 时间限制: 1000 ms 内存限制: 524288 KB sol:这题应该挺水的吧,就像个板子一样 1 0 01 1 0 * ...
- C# 汉字排序
转载:http://blog.csdn.net/lgx040605112/article/details/6042316 using System; using System.Globalizatio ...
- windows10中远程登录ubuntu16.04的桌面
1. 安装xrdp sudo apt-get install xrdp 2. 安装vnc4server sudo apt-get install vnc4server tightvncserver ...
- SQL 优化经验总结34条
我们要做到不但会写SQL,还要做到写出性能优良的SQL,以下为笔者学习.摘录.并汇总部分资料与大家分享! (1) 选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE 的解析器按照 ...
- 自学huawei之路-6005-8AP设备启动界面
返回自学Huawei之路 自学huawei之路-AC6005-8AP设备启动界面 [YK-MES-MASTER] Please check whether system data has been c ...
- 【转】ubuntu 12.04下如何开启 NFS 服务 & 设置
在嵌入式Linux开发中,利用NFS服务从开发板访问Linux主机是个高效&方便的调试方法,在程序调试过程中可以避免多次下载程序到开发板.但这需要在Linux主机上首先开通NFS服务. 以ub ...
- JavaScript学习复习
JavaScript 输出 使用 window.alert() 弹出警告框. 使用 document.write() 方法将内容写到 HTML 文档中. 使用 innerHTML 写入到 HTML 元 ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- list对象指针与指针类型list
#include <string> #include <cctype> #include <algorithm> #include <iostream> ...
- 【hihocoder】二分·归并排序之逆序对
描述 在上一回.上上回以及上上上回里我们知道Nettle在玩<艦これ>.经过了一番苦战之后,Nettle又获得了的很多很多的船.这一天Nettle在检查自己的舰队列表:我们可以看到,船默认 ...