无法从'转换为'?

时间:2016-02-03 10:36:26

标签: c# ado.net

此错误显示为enter image description here

**我有此错误无法从'转换为' **

    using SCB_Common.ExtensionMethods;
using System.Data.SqlClient;

namespace SCB_Common.DataBase
{
    public class BusinessCommon
    {
        public static void SetCommonCloumns(SqlDataReader DR, EntityCommon entity)
        {
            entity.CreatedAt = DR.GetDateTime("CreatedAt");
            entity.CreatedBy = DR.GetDecimal("CreatedBy");

            entity.LastModifyAt = DR.GetDateTime("LastModifyAt");
            entity.LastModifyBy = DR.GetDecimal("LastModifyBy");
            entity.ModifyBy = DR.GetDecimal("ModifyBy");

            entity.PostStateAt = DR.GetDateTime("PostStateAt");
            entity.PostStateBy = DR.GetDecimal("PostStateBy");

            entity.RecordState = DR.GetInt32("RecordState");
            entity.I_D = DR.GetDecimal("I_D");
        }
    }
}

**这是我调用SCB_Common.DataBase.BusinessCommon.SetCommonCloumns(DR,entity)时的方法获取记录;  **

 public Entity.SBH_D_Guardianship_Type_Entity GetRecord(Entity.SBH_D_Guardianship_Type_Entity ent, out bool IsDeleted)
    {
        IsDeleted = true;
        Entity.SBH_D_Guardianship_Type_Entity entity = null;

        SqlDataReader DR = Action.GetDataList(ent, 1, 1, "");
        while (DR.Read())
        {
            IsDeleted = false;

            entity = new Entity.SBH_D_Guardianship_Type_Entity();
            entity.ID = DR.GetDecimal("ID");
            entity.Aname = DR.GetString("Aname");
            entity.Ename = DR.GetString("Ename");

            SCB_Common.DataBase.BusinessCommon.SetCommonCloumns(DR, entity);
        }
        DR.Close();

        return entity;
    }

这是类实体

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SCB_HR_Business.Entity
{
   public class SBH_D_Guardianship_Type_Entity
    {
        public decimal ID_Co
        { get; set; }

        public decimal ID
        { get; set; }
        public string Aname
        { get; set; }
        public string Ename
        { get; set; }
        public decimal I_D
        { get; set; }

        public object LastModifyBy { get; set; }

        public object CreatedBy { get; set; }
    }
}

1 个答案:

答案 0 :(得分:1)

类型SBH_D_Guardianship_Type_Entity不是EntityCommon,我的意思是,它不是来自EntityCommon的继承。方法SetCommonCloumns除了作为EntityCommon对象的第二个参数。试试吧:

public class SBH_D_Guardianship_Type_Entity : EntityCommon 
{
    public decimal ID_Co { get; set; }

    public decimal ID { get; set; }
    public string Aname { get; set; }
    public string Ename { get; set; }
    public decimal I_D { get; set; }
}

请记住删除您在EntityCommon上定义的属性。