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
前面的两篇反应很差:没评论没赞.很伤心啊,为什么呢?搞得我好长一段时间都没更新了——呵呵,好吧,我承认,这只是我的借口.不过,还是希望大家多给反馈.没有反馈,我就只能猜了:前面两篇是不是写得太“粗”了 ...
随机推荐
- 【模板】Floyd
int n; ][MAX_N + ]; void Floyd() { ; k <= n; ++k) { ; i <= n; ++i) { ; j <= n; ++j) { d[i][ ...
- Antenna Placement POJ - 3020 (最小边集覆盖)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10699 Accepted: 526 ...
- MT【174】凹凸无妨
已知函数$f(x)=|x^3+3x^2-ax-b|$,对任意$a,b\in R$存在$x\in[-3,0]$使得$f(x)\le m$成立,求$m$的范围.求 $\displaystyle\min_{ ...
- MT【98】三元对称不等式
评:这是一道浙江省省赛题,这里利用对称性,设$x\le y\le z$从而解决了问题.值得注意的是此处三元轮换对称正好也是完全对称,但如果变成一般的$n\ge4$元对称问题时,就不能设大小关系.事实上 ...
- 【题解】 bzoj1597: [Usaco2008 Mar]土地购买 (动态规划+斜率优化)
bzoj1597懒得复制,戳我戳我 Solution: 线性DP打牌\(+\)斜率优化 定义状态:\(dp[i]\)到了位置\(i\)最少花费 首先我们要发现,如果有一个小方块能被其他的大方块包围,其 ...
- hdu5449 Robot Dog (树形dp+倍增lca)
(警告:本篇博客包含大量人类本质内容) 先处理出来lca,然后就只需要知道从每个点到他的父亲.和从他的父亲到这个点的期望时间就可以了 我们设f[x]为x到他父亲的期望时间:g[x]为从x的父亲到x的期 ...
- 【uoj3】 NOI2014—魔法森林
http://uoj.ac/problem/3 (题目链接) 题意 给出一张带权图,每条边有两个权值A和B,一条路径的花费为路径中的最大的A和最大的B之和.求从1走到n的最小花费. Solution ...
- JavaScript--Dom间接选择器
一.Dom间接选择器 间接查找的属性 parentNode // 父节点 childNodes // 所有子节点 firstChild // 第一个子节点 lastChild // 最后一个子节点 n ...
- Mask RCNN 原理
转自:https://blog.csdn.net/ghw15221836342/article/details/80084861 https://blog.csdn.net/ghw1522183634 ...
- PAM认证机制详情
PAM(Pluggable Authentication Modules)认证机制详情 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.介绍PAM PAM(Plugga ...