I have a LINQ query I wish to run and drop the result into a var or IQueryable. However, I'm binding the result to multiple (4 to 10) controls and only want the query to run once.
- When I just put the result into all the datasource values, the query runs for every control and the controls (comboboxes, for example), change selectedvalues to match each other whenever any of them is changed.
- When I databind the controls to the result.ToList() or something similar, that fixes the synchronization problem (i.e. they behave independently as they should), but the query still runs once for every control.
This was easycakes in ADO.NET days. How can I make the LINQ query run once and still databind to multiple controls?
Pseudocode:
var result = from c in dc.whatevers select c;
ddlItem1.DataSource = result;
ddlItem2.DataSource = result;
ddlItem3.DataSource = result;
Also:
var result = from c in dc.whatevers select c;
ddlItem1.DataSource = result.ToList();
ddlItem2.DataSource = result.ToList();
ddlItem3.DataSource = result.ToList();
Also:
List<whatever> result = (from c in dc.whatevers select c).ToList();
ddlItem1.DataSource = result;
ddlItem2.DataSource = result;
ddlItem3.DataSource = result;