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的更多相关文章

  1. 【C#】使用NHibernate连接MySQL数据库及增删改查

    学习资料 http://www.sikiedu.com/course/51/task/891/show https://www.codeproject.com/Articles/26123/NHibe ...

  2. 使用NHibernate连接MySQL数据库及增删改查

    学习资料 http://www.sikiedu.com/course/51/task/891/show https://www.codeproject.com/Articles/26123/NHibe ...

  3. 利用NHibernate与MySQL数据库交互

    本文章使用Visual Studio作为开发工具,并建立在已经安装MySQL数据库的前提. NHibernate是一个面向.NET环境的对象/关系数据库映射工具.官网:http://nhibernat ...

  4. Fluent NHibernate and Mysql,SQLite,PostgreSQL

    http://codeofrob.com/entries/sqlite-csharp-and-nhibernate.html https://code.google.com/archive/p/csh ...

  5. MySql(一)_利用NHibernate和MySql交互

    1.基础配置,添加MySql和nHibernate的引用 (1)   添加引用,导入MySql.data.dll:   利用MySql提供的API操作: (2) 添加引用,导入NHibernate.d ...

  6. NHibernate+MySql (erro 解决方法)

    error1.  Could not create the driver from NHibernate.Driver.MySqlDataDriver 解决方法:在使用Nhibernate连接Mysq ...

  7. [NHibernate] 入门实例 NHibernate 3.3 GA + VS2010 +MySQL

    题外话: 中国的技术论坛要赶上stackoverflow的水平.至少还需35年.中国程序猿笔者的特点是:太浮躁,太easy下总结.太自得其乐,虽说写的是为了让别人更好的看.却也演变成了一种" ...

  8. 【NHibernate】列“ReservedWord”不属于表 ReservedWords

    NHibernate+FluentNHibernate+MySql 运行时黄页显示下边的异常,项目中找了半天没出现过这个列的关键字. [ArgumentException: 列“ReservedWor ...

  9. 架构之路(九)Session Per Request

    前面的两篇反应很差:没评论没赞.很伤心啊,为什么呢?搞得我好长一段时间都没更新了——呵呵,好吧,我承认,这只是我的借口.不过,还是希望大家多给反馈.没有反馈,我就只能猜了:前面两篇是不是写得太“粗”了 ...

随机推荐

  1. springMVC的接受参数三种样例

  2. 一本通1633【例 3】Sumdiv

    1633:[例 3]Sumdiv 时间限制: 1000 ms         内存限制: 524288 KB [题目描述] 原题来自:Romania OI 2002 求 ABAB 的所有约数之和 mo ...

  3. MySQL索引类型,优化,使用数据结构

    工欲善其事必先利其器 半藏说道:“若你在路途中遇到上帝,上帝也会被割伤.” 一.mysql 索引分类(默认使用B树结构)在数据库表中,对字段建立索引可以大大提高查询速度.通过善用这些索引,可以令 My ...

  4. MT【77】函数的定义理解

    答案:D.比如C 中令$x^2+1=2,x=-1,1,$ 得$f(2)=0,2$与定义矛盾,A,B同理排除. D中注意到$x^2-2x$与$|x-1|$对称轴都是$x=1$. 评:函数的定义,首先是两 ...

  5. Linux通过端口转发来访问内网服务(端口转发访问阿里云Redis数据库等服务)

    # 安装rinetd wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xvf rinetd.tar.gz& ...

  6. 同一台机器安装多个MySQL服务

    在同一个服务器上面安装多个MySQL服务,甚至是安装多个不同版本(比如5.7和5.7.5.7和8.0.12),关键在于区分安装目录.数据目录和使用端口等. 可以下面步骤 安装MySQL1 wget h ...

  7. 一个具有缓存数据功能的HttpWebRequest工具类

    背景:一个公共站点中的数据,供其它子站点共享,为了提高性能,简单实现了Http 1.1的缓存功能 特点:可以缓存Html数据到内存中;缓存具有过期时间;缓存过期后,通过再确认的方式来决定是否更新缓存; ...

  8. 以Java的视角来聊聊BIO、NIO与AIO的区别?

    转: 以Java的视角来聊聊BIO.NIO与AIO的区别? 飞丫玲丫 17-07-2623:10 题目:说一下BIO/AIO/NIO 有什么区别?及异步模式的用途和意义? BIO(Blocking I ...

  9. Mask-RCNN数据集制作

    转自https://blog.csdn.net/pingushen2100/article/details/80513043 一.Mask-RCNN数据集 1.1 训练Mask-RCNN用的到的文件有 ...

  10. vs2015的visual assist X options安装过程

    1.安装VA_X之前,请先关闭VS2015程序. 2.下载VA_X_Setup2048.exe和VAX2048破解补丁.zip. 3.双击运行VA_X_Setup2048.exe文件,安装完成后出现 ...