我尝试写一些代码通过下面的代码有关生成匿名类型列表:如何填写匿名类型列表?
public static List<T> MakeList<T>(T itemOftype)
{
List<T> newList = new List<T>();
newList.Add(itemOftype);
return newList;
}
但返回错误。我:
通过 KeyFieldName属性指定一个主键字段中找不到 底层数据源。确保 字段名拼写正确。 注意字符大小写。
Main.cs
var Qry = from tableRaletions in taskMaints.TaskRelations
where tableRaletions.TaskId == Convert.ToInt32(txtID.Text) && tableRaletions.RelTypeId == 12
select new
{
tableRaletions.RefMaintenance.code,
tableRaletions.RefMaintenance.shortdesc
};
GridMaintenanceData.DataSource = SetCalculatedTaskField.MakeList(Qry);
GridMaintenanceData.DataBind();
我试图从任何类返回列表值,但我必须列出定义... –
Penguen
2010-08-13 10:30:38
更糟糕的是比MakeList方法简单地返回一个列表包含itemOftype变量传递给它的单个项目。 'SetCalculatedTaskField.MakeList(Qry)'将返回一个列表,其中包含一个带有'Qry'的项目,它不会返回'Qry'作为列表。 – 2010-08-13 13:20:37