Merging ILists to bind on datagridview to avoid using a database view
- by P.Bjorklund
In the form we have this where IntaktsBudgetsType is a poorly named enum that only specifies wether to populate the datagridview after customer or product (You do the budgeting either after product or customer)
private void UpdateGridView() {
bs = new BindingSource();
bs.DataSource = intaktsbudget.GetDataSource(this.comboBoxKundID.Text, IntaktsBudgetsType.PerKund);
dataGridViewIntaktPerKund.DataSource = bs;
}
This populates the datagridview with a database view that merge the product, budget and customer tables.
The logic has the following method to get the correct set of IList from the repository which only does GetTable<T>.ToList<T>
public IEnumerable<IntaktsBudgetView> GetDataSource(string id, IntaktsBudgetsType type)
{
IList<IntaktsBudgetView> list = repository.SelectTable<IntaktsBudgetView>();
switch (type)
{
case IntaktsBudgetsType.PerKund:
return from i in list
where i.kundId == id
select i;
case IntaktsBudgetsType.PerProdukt:
return from i in list
where i.produktId == id
select i;
}
return null;
}
Now I don't want to use a database view since that is read-only and I want to be able to perform CRUD actions on the datagridview.
I could build a class that acts as a wrapper for the whole thing and bind the different table values to class properties but that doesn't seem quite right since I would have to do this for every single thing that requires "the merge".
Something pretty important (and probably basic) is missing the the thought process but after spending a weekend on google and in books I give up and turn to the SO community.