无法将类型 IQueryable 隐式转换为 class

Cannot implicitly convert type IQueryable to class

我正在尝试将多个结果放入列表中以发送回 JS 以填充网格。第一个查询 (_mappedQuery) 正在获取数据。然后我想最终将这些值放入 _udfList 对象中。我不断收到错误 'cannot convert queryable to class'

的差异

我试过设置为列表、创建查询对象、单个 class 对象。到目前为止都没有运气

            MemberMNCFormsList _udfList = new MemberMNCFormsList();

            foreach (var _row in _udfTables) {
                System.Diagnostics.Debugger.Break();
                System.Diagnostics.Debugger.Launch();

                var _mappedQuery = (from res in Query<UdfColumnMapping>().AsNoTracking()
                                    join udf in Query<UserDefinedForms>().AsNoTracking() on res.Func_Area equals udf.Func_Area
                                    join ds in Query<Data_Set>().AsNoTracking() on res.Data_ID equals ds.DATA_ID
                                    join df in Query<DEFITEM>().AsNoTracking() on ds.DEF_ID equals df.DEF_ID
                                    where udf.UserDefinedForms_ID == _row.UserDefinedForms_ID &&
                                     (res.FieldName.ToLower().StartsWith("reviewname") ||
                                     res.FieldName.ToLower().StartsWith("disposition") ||
                                     res.FieldName.ToLower().StartsWith("reviewdate"))
                                    select (new MemberMNCForms {
                                        UserDefinedFormData_ID = _row.UserDefinedFormData_ID,
                                        FormId = udf.UserDefinedForms_ID,
                                        MappedColumnName = res.MappedColumnName,
                                        FieldName = res.FieldName,
                                        MappedTableName = res.MappedTableName,
                                        Reviewed_Name = _row.LAST_NAME.Trim() + ", " + _row.FIRST_NAME.Trim(),
                                        Reviewed_Date = _row.CreateDate.GetShortDateorEmpty().ToString()
                                    }));

                var _formRow = _mappedQuery.Select(t => new MemberMNCForms {
                    UserDefinedFormData_ID = t.UserDefinedFormData_ID,
                    FormId = t.FormId,
                    MappedColumnName = t.MappedColumnName,
                    FieldName = t.FieldName,
                    MappedTableName = t.MappedTableName,
                    Reviewed_Name = t.Reviewed_Name,
                    Reviewed_Date = t.Reviewed_Date
                })));

                _udfList.list.Add(_formRow);

   public sealed class MemberMNCForms {
        public Guid? UserDefinedFormData_ID { get; set; }
        public int FormId { get; set; }
        public string Reviewed_Name { get; set; }
        public string MappedColumnName { get; set; }
        public string FieldName { get; set; }
        public string MappedTableName { get; set; }
        public int? MNCDetermination_ID { get; set; }
        public string Reviewed_By { get; set; }
        public string Reviewed_Date { get; set; }
    }

    public sealed class MemberMNCFormsList : ErrorInfo
    {
        public List<MemberMNCForms> list = new List<MemberMNCForms>();
        public int Count { get; set; }
    }

我正在尝试使用来自 _mappedQuery 的值填充 _udfList 对象。我认为唯一可行的是为 _mappedQuery 中的每条记录创建一个 MemberMNCForms 对象,然后添加到 _udfList.list

当你像那样使用 linq 时,即使列表中只有一个项目Select在其上,它也只是一个表达式树,直到它被迭代。

我假设您希望返回 MemberMNCForms 的集合,因此您需要使用 AddRange 而不是 Add

_udfList.list.AddRange(_formRow);

要确定是否已经执行,可以使用ToList

_udfList.list.AddRange(_formRow.ToList());

如果您只需要一个结果,可以使用 SingleOrDefault

var result = _formRow.SingleOrDefault();
if (result != null) {
    _udfList.list.Add(result);
}

_formRow 是一个 IEnumerable<MemberMNCForms>

var _formRow = _mappedQuery.Select(t => new MemberMNCForms {
    UserDefinedFormData_ID = t.UserDefinedFormData_ID,
    FormId = t.FormId,
    MappedColumnName = t.MappedColumnName,
    FieldName = t.FieldName,
    MappedTableName = t.MappedTableName,
    Reviewed_Name = t.Reviewed_Name,
    Reviewed_Date = t.Reviewed_Date
})));

您在这里尝试将 IEnumerable<MemberMNCForms> 添加到 List<MemberMNCForms>

_udfList.list.Add(_formRow);

您无法使用 .Add 执行此操作。你必须使用 .AddRange

试试这个:

_udfList.list.AddRange(_formRow);