IBatis.Net如何支持多个数据库 [转帖]

在Ibatis.net的帮助文档中有介绍多数据库支持,但是没有写全代码,后来查看其源码,并结合帮助文档,找到了解决方法,其实道理就是另行实现一个Mapper.如AnthorMapper: Apache

 

Code

 

以上代码只是修改了IBatis.net中的Mapper的代码,将_mapper = builder.ConfigureAndWatch (handler);修改为_mapper = builder.ConfigureAndWatch ("AnthorMap.config",handler),就是根据另一个AnthorMap.config文件来生成SqlMapper。

AnthorMap.config和默认的SqlMap.config一样,只是根据你的数据不同设置不同而已,测试AnthorMap.config如下如下:

 

Code

 

接下来就可以使用AntherMapper来创建ISqlMapper了。如下:

 

Code
posted @ 2009-02-24 15:37  狂歌  阅读(1440)  评论(0编辑  收藏  举报