The type of var is an anonymous type. You can not return values of anonymous type from functions in C# 3.0. You should be able to mouse-over q in visual studio and see it's 'real' type (which you can define as your return type), but given your code, the value of the group is an anonymous class, which you can't use if you want a strongly-typed return value. I think this should work though:
public class GroupInfo
{
public string Description { get; set; }
public object FieldValue { get; set; }
}
public List<IGrouping<string, GroupInfo>> Custom_GroupedAFVList(Int32 intSPIDItemID)
{
var q = from c in new context.vw_AFValueGridListing
where c.SPIDID == intSPIDItemID
orderby c.DisplayOrder
group new GroupInfo()
{
Description = c.Description,
FieldValue = c.FieldValue
}
by c.GroupName;
return q.ToList();
}
I would think a Dictionary<K,List<V>> would be easier to work with as a result in a scenario like this than an IEnumerable<IGrouping<K,V>> though, and it's not hard to change to that:
public Dictionary<string, List<GroupInfo>> Custom_GroupedAFVList(Int32 intSPIDItemID)
{
var q = ....
return q.ToDictionary(i => i.Key, i => i.ToList());
}
:)
Niladri Biswas