I have a List<T> that is holding several objects called tc of type TwitterCollection. Each instance of tc contains 5 properties.
The TwitterCollection class looks like this:
public class TwitterCollection
{
public string origURL { get; set; }
public string txtDesc { get; set; }
public string imgURL { get; set; }
public string userName { get; set; }
public string createdAt { get; set; }
}
I am running a Linq to objects statement as such:
var counts = from tc in sList
group tc by tc.origURL into g
orderby g.Count()
select new { myLink = g.Key, Count = g.Count() };
Now the problem I have is that I can’t access any of the tc properties. I can access the origURL no problem, as it is assigned to g… but the txtDesc, imgURL and the other properties seem inaccessible. I need the above statement in order to sort my data appropriately.
How can I modify my Linq statement to include all the other properties of tc, plus for it to still be sorted/ordered by Count() in the way it is now.
You’ve grouped the results – so which username would you expect to get? The group is a whole sequence of elements, all with the same URL. If you want to use the first one, you could do something like:
You could then do:
If you want the whole group, then just select it:
Admittedly at that point, there’s not much point in having
Countseparately – you could just do:You can then use: