当前位置:编程学习 > C#/ASP.NET >>

关于 .net 中使用IBatis的问题,在线等

小弟在做一个用IBatis技术的.net项目,现在有一个问题,弄了一通宵也弄不出来,在线等回复,请大家帮忙看看
sqlMap:
<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="PcDepartmentTMap" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ibatis.apache.org/mapping">

  <alias>

    <typeAlias alias="Department" type="Permissions.Domain.Department,Domain" />

  </alias>

  <resultMaps>

    <resultMap id="PcDepartmentTResult" class="Department">
      <result property="Id" column="ID" type="int" />
      <result property="Name" column="NAME" type="string" />
      <result property="Code" column="CODE" type="string" />
      <result property="Description" column="DESCRIPTION" type="string" />
      <result property="SuperiorDeptId" column="SUPERIORDEPTID" type="int"/>
      <result property="InUse" column="INUSE" type="string" />
    </resultMap>
  </resultMaps>
  <statements>

    <select id="SelectPcDepartmentT" parameterClass="int"  resultMap="PcDepartmentTResult">
      SELECT ID AS Id,NAME AS Name,CODE AS Code,DESCRIPTION AS Description,SUPERIORDEPTID AS SuperiorDeptId,INUSE AS InUse
      FROM PC_DEPARTMENT_T
      where id = #value#
      <!--<dynamic prepend="WHERE">
        <isParameterPresent>
          ID = #value#
        </isParameterPresent>-->
        <!--<isParameterPresent>
          SUPERIORDEPTID = #value#
        </isParameterPresent>-->
      <!--</dynamic>-->
    </select>
    <insert id="InsertPcDepartmentT" parameterClass="Department">
      INSERT INTO PC_DEPARTMENT_T
      (ID,NAME,CODE,DESCRIPTION,SUPERIORDEPTID,INUSE)
      VALUES(s_pc_department_t.nextval,#Name#,#Code#,#Description#,decode(#SuperiorDeptId#,0,null,#SuperiorDeptId#),#InUse#)
    </insert>
    <update id="UpdatePcDepartmentT" parameterClass="Department">
      UPDATE PC_DEPARTMENT_T
      SET NAME=#Name#,CODE=#Code#,DESCRIPTION=#Description#,SUPERIORDEPTID=decode(#SuperiorDeptId#,0,null,#SuperiorDeptId#),INUSE=#InUse#
      WHERE ID = #Id#
    </update>
    <delete id="DeletePcDepartmentT" parameterClass="int">
      DELETE FROM PC_DEPARTMENT_T
      WHERE ID = #value#
    </delete>
  </statements>
</sqlMap>
Dao:
namespace Permissions.DataAccess
{
    public class DepartmentDao : DaoSupport<Department,int>,  IDepartmentDao
    {
        public Department FindByPk(int pk)
        {
            ISqlMapper sqlMap = Mapper.Instance();
            return sqlMap.QueryForObject("SelectPcDepartmentT", pk) as Department;
        }

        public IList<Department> FindSubDepartments(int superDeptId)
        {
            ISqlMapper sqlMap = Mapper.Instance();
                                               
            return sqlMap.QueryForList<Department>("SelectPcDepartmentT", superDeptId);
        }

        public bool DeleteDepartmentByPk(int pk)
        {
            ISqlMapper sqlMap = Mapper.Instance();

            try
            {
                sqlMap.Delete("DeletePcDepartmentT", pk);
            }
            catch
            {
                return false;
            }

            return true;
        }

        public bool UpdateItem(Department department)
        {
            ISqlMapper sqlMap = Mapper.Instance();

            try
            {
                sqlMap.Update("UpdatePcDepartmentT", department);
            }

            catch
            {
                return false;
            }

            return true;
        }

        public bool CreateItem(Department department)
        {
            ISqlMapper sqlMap = Mapper.Instance();

            try
            {
                sqlMap.Insert("InsertPcDepartmentT", department);
            }
            catch
            {
                return false;
            }

            return true;
        }
    }
}

问题如下:
    1、执行语句return sqlMap.QueryForObject("SelectPcDepartmentT", pk) as Department;总是返回空
    2、执行语句sqlMap.Delete("DeletePcDepartmentT", pk);直接就卡住,不能执行下句了
我的分析:
    1、可以肯定问题就处在上述两条语句上,因为注释掉之后跑的很畅通
    2、数据库已经连接上,没有问题

小弟没有分,我一通宵没睡了,在线等,希望大家能帮帮忙,谢谢大家乐先 --------------------编程问答-------------------- parameterClass="System.Int32"

那两个出错的你改过来试试看
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,