programmerist 1983
asked on
How can i fill Anonymous type in list?
I try to write some codes about Generate list from Anonymous type via below codes :
A primary key field specified via the KeyFieldName property is not found in the underlying data source. Make sure the field name is spelled correctly. Pay attention to the character case.
Main.cs
Please don't say why directly return Tolist(). i know it but i need above....
public static List<T> MakeList<T>(T itemOftype)
{
List<T> newList = new List<T>();
newList.Add(itemOftype);
return newList;
}
But ERROR return me:A primary key field specified via the KeyFieldName property is not found in the underlying data source. Make sure the field name is spelled correctly. Pay attention to the character case.
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();
Please don't say why directly return Tolist(). i know it but i need above....
var Qry - already has a method named 'ToList()' and you can use that like:
GridMaintenanceData.DataSo
Grid's datasource will work with the list returned by Qry.ToList();
Just saw the last line in your question...then...
it seems the issue is not with MakeList, but in the linq query....from the error message it looks like - taskMaints.TaskRelations doesn't have the key field name....
hello,
maybe i am wrong but,
don't you need to make the call SetCalculatedTaskField.Mak eList(Qry) with using a type;
like SetCalculatedTaskField.Mak eList<Clas sA>(itemTy peOfClassA );
maybe i am wrong but,
don't you need to make the call SetCalculatedTaskField.Mak
like SetCalculatedTaskField.Mak
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Which line is throwing this error?
see if this helps you
http://community.devexpress.com/forums/p/81912/280307.aspx
Thanks and regards,
Venki