0

我的结果表达式是

 var result = dtFields.AsEnumerable().Join(dtCDGroup.AsEnumerable(),
                                fieldList=>fieldList.Field<string>("CDGroupID"),
                                cd=>cd.Field<string>("CDGroupID"),
                                (fieldList,cd) => new 
                                {
                                    FieldID = fieldList.Field<string>("FieldID"),
                                    Name = cd.Field<string>("Name"),
                                    CDCaption = fieldList.Field<string>("CDCaption"),
                                    Priority = ((cd.Field<string>("Priority") == null) ? 99 : cd.Field<int>("Priority")),
                                    fldIndex = fieldList.Field<string>("fldIndex")
                                }).OrderBy(result => result.Priority).ThenBy(result => result.fldIndex);

将上述结果转换为数组或列表会引发无效的转换异常。如何提取上述表达式的结果?

4

2 回答 2

2

Add .ToArray() or .ToList() call respectively

于 2012-04-17T10:29:00.327 回答
0

尝试添加一个强类型:

public class NewModule
{
    public int FieldID { get; set; }
    public string Name { get; set; }
    public string CDCaption { get; set; }
    public int Priority { get; set; }
    public int fldIndex { get; set; }
}

而不是匿名类型,那么您可以ToList<NewModule>()像这样使用:

var result = dtFields.AsEnumerable().Join(dtCDGroup.AsEnumerable(),
                            fieldList=>fieldList.Field<string>("CDGroupID"),
                            cd=>cd.Field<string>("CDGroupID"),
                            (fieldList,cd) => new NewModule
                            {
                                FieldID = fieldList.Field<string>("FieldID"),
                                Name = cd.Field<string>("Name"),
                                CDCaption = fieldList.Field<string>("CDCaption"),
                                Priority = ((cd.Field<string>("Priority") == null) ? 99 : cd.Field<int>("Priority")),
                                fldIndex = fieldList.Field<string>("fldIndex")
                            }).OrderBy(result => result.Priority)
                            .ThenBy(result => result.fldIndex)
                            .ToList<NewModule>();
于 2012-04-17T10:41:54.720 回答