项目中基于Rest的Wcf服务发布以及iBatisNet框架的使用(下)

iBatisNet框架的配置使用:iBatisNet框架的好处,有很多技术文档中有描述,在此只记录如何在项目中配置使用此框架。首先 在DAL层中添加引用:IBatisNet.DataMapper.dll和IBatisNet.Common.dll,然后在DAL层添加一个BaseService.cs文件,在这个类中定义一个SqlMap属性,目的是为了实现IBatisNet.DataMapper中ISqlMapper接口,并通过IbatisConfig.DomSqlMapBuilder中的Configure方法对属性赋值。代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ibatis = IBatisNet.DataMapper;
using IbatisConfig = IBatisNet.DataMapper.Configuration;

namespace MyProject.DAL
{
public class BaseService
{
private static Ibatis.ISqlMapper sqlMap;

public BaseService()
{
IbatisConfig.DomSqlMapBuilder sqlMapBuilder = new IbatisConfig.DomSqlMapBuilder();
sqlMap = sqlMapBuilder.Configure();
}
public Ibatis.ISqlMapper SqlMap
{
get
{
return sqlMap;
}
}
}
}

然后,在Web项目中添加Providers.config和sqlmap.config两个文件,Providers.config主要包含了支持的数据库类型及版本,sqlmap.config是主要的配置文件,可以配置数据库连接字符串,并通过 <sqlMap resource="Map/Person.xml" />来增加新的xml。通过IBatisToolsWeb工具,可以生成数据库中的表相对应的DAL层、实体类层(Module层)、Xml文件,注意把新生成的Xml以<sqlMap resource="Map/Person.xml" />的形式添加到sqlmap.config的<sqlMaps>节点中。至此,全部配置完毕。

原文地址:https://www.cnblogs.com/arthur20101108/p/2334810.html