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
前面的两篇反应很差:没评论没赞.很伤心啊,为什么呢?搞得我好长一段时间都没更新了——呵呵,好吧,我承认,这只是我的借口.不过,还是希望大家多给反馈.没有反馈,我就只能猜了:前面两篇是不是写得太“粗”了 ...
随机推荐
- EntityFramework异常The specified cast from a materialized 'System.Double' type to the 'System.Single' type is not valid.
实体类: public class ReportEntity { public string FactorName { get; set; } public double MaxVal { get; ...
- pgm5
这部分讨论 inference 里面基本的问题,即计算 这类 query,这一般可以认为等价于计算 ,因为我们只需要重新 normalize 一下关于 的分布就得到了需要的值,特别是像 MAP 这类 ...
- 【拓扑 字符串还原 + 线段树维护】奇洛金卡达(father)
奇洛金卡达(father) Description 阿良良木历将要迎来人生(不,是吸血鬼生涯)的第三次战斗——与身为人类的奇洛金卡达在直江津高中的操场solo,以取回Heartunderblade 的 ...
- luogu4155/bzoj4444 国旗计划 (倍增)
成环,把每个区间变成两个然后展开成链 一个人的下一个人肯定是在彼此相交的基础上,右端点越大越好 于是就把它连到相交的.右端点最大的点上,连成一棵树 于是每次只要从某个节点开始,一直在树上跳到覆盖了一个 ...
- 【UVA1401】Remember the Word Trie+dp
题目大意:给定一个字符串和一个字符串集合,问从集合中选出若干个串组成给定母串的不同方案数. 题解:有些类似于背包问题.状态很好表示,为:\(dp[i]\) 表示母串前 i 个字符的不同方案数,因此,有 ...
- Linux上软件安装
手动安装 以安装SublimeText3为例: 首先下载安装包 [keysystem@localhost ~]$ wget https://download.sublimetext.com/subli ...
- Logistic回归中损失函数求导证明过程
- ELK logstash 处理MySQL慢查询日志
在生产环境下,logstash 经常会遇到处理多种格式的日志,不同的日志格式,解析方法不同.下面来说说logstash处理多行日志的例子,对MySQL慢查询日志进行分析,这个经常遇到过,网络上疑问也很 ...
- Java基础-Java中23种设计模式之常用的设计模式
Java基础-Java中23种设计模式之常用的设计模式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.设计模式分类 设计模式是针对特定场景给出的专家级的解决方案.总的来说设 ...
- A*算法–A* algorithm tutorial
Author:Justin Heyes-Jones From: http://heyes-jones.com/astar.php Date:2014.8.16 本文地址:http://www.cnbl ...