Reputation: 1621
I am retrieving data from an Access database using CoolStorage
, and can successfully populate a Team DataGridView
by setting its DataSource as Team.List()
.
However, I want to use a LINQ query on the result set to return the number of users for each team. As this screenshot shows the result is being returned fine, however the DataGridView
displays no data. If I switch the DataSource
to be Team.List()
it displays the teams without any problems (though obviously not the number of users).
Is there something I need to do in order to use the LINQ result as a DataSource? I can get round this by adding a property to my Team class, however I don't understand why I can't use the LINQ result.
Upvotes: 0
Views: 1108
Reputation: 450
LINQ uses deferred execution. That is, you have built your LINQ query but it will not actually be evaluated to produce results unless you add a method or aggregate on the end of the query to force immediate evaulation, or you can enumerate the result.
Try using...
this.dgvTeams.DataSource = d.ToList();
Upvotes: 1
Reputation: 18162
You will need to materialize your datasource before it can be used.
Try changing
this.dgvTeams.DataSource = d;
to
this.dgvTeams.DataSource = d.ToList();
Upvotes: 3