I am using LINQ to query a generic dictionary and then use the result as the datasource for my ListView (WebForms).
Simplified code:
Dictionary
Try this:
var matches = dict.Values.Where(rec => rec.Name == "foo").ToList();
Be aware that that will essentially be creating a new list from the original Values collection, and so any changes to your dictionary won't automatically be reflected in your bound control.
You might also try:
var matches = new List<Record>(dict.Values.Where(rec => rec.Name == "foo"));
Basically generic collections are very difficult to cast directly, so you really have little choice but to create a new object.
Just adding knowledge the next sentence doesn´t recover any data from de db. Just only create the query (for that it is iqueryable type). For launching this query you must to add .ToList() or .First() at the end.
dict.Values.Where(rec => rec.Name == "foo")
I tend to prefer using the new Linq syntax:
myListView.DataSource = (
from rec in GetAllRecords().Values
where rec.Name == "foo"
select rec ).ToList();
myListView.DataBind();
Why are you getting a dictionary when you don't use the key? You're paying for that overhead.
myListView.DataSource = (List<Record>) dict.Values.Where(rec => rec.Name == "foo");