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
原文地址:https://www.cnblogs.com/daxia/p/1397289.html