使用Linq

时间:2015-12-18 00:48:06

标签: linq datatable

您有此代码,我希望此函数返回CLS_EL_ARCHIVE对象列表但我收到此错误: ' CLS_EL_ARCHIVE'不包含带0参数的构造函数

public override IEnumerable<CLS_EL_ARCHIVE> GetAll()
    {
        DataTable DT = DAC.SelectData("SP_GET_ALL", new SqlParameter[] { new SqlParameter("@Table", "ARCHIVE") });
        List<CLS_EL_ARCHIVE> ArchiveList = new List<CLS_EL_ARCHIVE>();
        ArchiveList = DT.AsEnumerable().Select(Row => new CLS_EL_ARCHIVE
        {
            ArchiveId = Row.Field<int>("ArchiveId"),
            Label = Row.Field<string>("Label"),
            Date = Row.Field<DateTime>("Date"),
            Note = Row.Field<string>("Note")
        });
        return ArchiveList;
    }

1 个答案:

答案 0 :(得分:0)

这对我有用:)等待更多答案

DataTable DT = DAC.SelectData("SP_GET_ALL", new SqlParameter[] { new SqlParameter("@Table", "ARCHIVE") });
        List<CLS_EL_ARCHIVE> ArchiveList = new List<CLS_EL_ARCHIVE>();
        ArchiveList = DT.AsEnumerable().Select(Row => new CLS_EL_ARCHIVE(Row.Field<int>("ArchiveId"), Row.Field<string>("Label"),
            Row.Field<DateTime>("Date"), Row.Field<string>("Note"))).ToList();