IBatisNet菜鸟,请教点问题!
我的配置文件dao.config<?xml version="1.0" encoding="utf-8"?>
<daoConfig
xmlns="http://ibatis.apache.org/dataAccess"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<providers resource="providers.config"/>
<context id="AccessMapDao" default="true">
<database>
<provider name="OleDb2.0" />
<dataSource name="Access" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\NEWS\NEWS\App_Data\demo.mdb;" />
</database>
<daoSessionHandler id="SqlMap">
<property name="resource" value="sqlMap.config"/>
</daoSessionHandler>
<daoFactory>
<dao
interface="YTO.Intranet.News.IDAL.IMajorNewsDao, NEWS"
implementation="YTO.Intranet.News.DAL.MajorNewsDao, NEWS"/>
</daoFactory>
</context>
</daoConfig>
我的配置文件sqlMap.comfig
<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<properties resource="providers.config"/>
<properties embedded="dao.config, NEWS"/>
<settings>
<setting useStatementNamespaces="true"/>
</settings>
<sqlMaps>
<sqlMap resource="NEWS/sqlMaps/MajorNews.config"/>
</sqlMaps>
</sqlMapConfig>
我用了一个BLL层来作为对数据库的操作
public class MajorNewsBiz
{
private IDaoManager daoManager;
private IMajorNewsDao majorNewsDao;
public MajorNewsBiz()
{
daoManager = ServiceConfig.GetInstance().DaoManager;
majorNewsDao = daoManager.GetDao(typeof(IMajorNewsDao)) as IMajorNewsDao;
}
}
直接运行的话报configurationException错:
- The error occurred while configure DaoSessionHandler.
- The error occurred in <property name="resource" value="sqlMap.config" xmlns="http://ibatis.apache.org/dataAccess" />.
- Check the IBatisNet.DataAccess.DaoSessionHandlers.SqlMapDaoSessionHandler.
然后我把dao.config中的
<daoSessionHandler id="SqlMap">
<property name="resource" value="sqlMap.config"/>
</daoSessionHandler>
给注释掉了之后运行!
报DataAccessException错误:
DaoProxy : unable to intercept method name 'FindAllMajorNews', cause : 无法将类型为“IBatisNet.DataAccess.DaoSessionHandlers.SimpleDaoSession”的对象强制转换为类型“IBatisNet.DataAccess.DaoSessionHandlers.SqlMapDaoSession”。
这个到底是什么原因啊!
我下载了价格Demo看了下,一样的配置啊,没什么问题啊!
是不是我创建sqlMap.config的时候错误啊,我是创建的命名为sqlMap.config的配置文件!
然后那个IBatisNet的三个dll文件也是拷进去了,然后添加的引用!
哪位大侠帮我看看啊!着急啊!都困了好几天了!
--------------------编程问答-------------------- up 接分 --------------------编程问答-------------------- 你配置数据源有问题,需要在ibatis的dao.config中配置数据源,文件名不影响。 --------------------编程问答-------------------- 楼上的能说清楚点吗?什么数据源?
<database>
<provider name="OleDb2.0" />
<dataSource name="Access" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\NEWS\NEWS\App_Data\demo.mdb;" />
</database>
不是这个吗? --------------------编程问答-------------------- 类型不一致
检查FindAllMajorNews方法 --------------------编程问答-------------------- public IList<MajorNewsInfo> FindAllMajorNews()
{ return Mapper.Instance().QueryForList<MajorNewsInfo>(WrapStatementName ("FindAllMajorNews"), null);
}
这个是我的FindAllMajorNews的方法啊
提示SimpleDaoSession和SqlMapDaoSession类型不一致,我看了下在IBatisNet中的确是SimpleDaoSession 和 SqlMapDaoSession都有啊! --------------------编程问答-------------------- 你的Dao里实现IDao接口了吗? --------------------编程问答-------------------- 没用过这个东西!
看下. --------------------编程问答-------------------- public IList<MajorNewsInfo> FindAllMajorNews()
{
return ExecuteQueryForList<MajorNewsInfo>("FindAllMajorNews", null);
}
--------------------编程问答-------------------- 接口肯定都实现了的! --------------------编程问答-------------------- 谁能给我一个确切的答案是什么原因啊?该怎么处理啊!
谢谢了,各位大侠! --------------------编程问答-------------------- 这个错误我知道
<sqlMap namespace="BondInfoModel" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SqlMap.xsd">
<alias>
<typeAlias alias="BondInfoModel" type="CS.DomainModel.BondInfoModel,DomainModel" />
</alias>
</sqlmap>
是你的typealias 里面的type错了!
补充:.NET技术 , C#