Hi all.
I have a question for you regarding EntityFrameWork and DataGridView. Actually this Q is more generic because it would be the same if using EntityFramework, DataSet/DataTable, Linq2Sql, etc. etc.
Ok. Here goes:
I have a DataGridView. This DataGridView is filled with data from a resultset of a LINQ request, something like this:
var records = from r in db.Customers
select new
{
Name = r.Name,
Address = r.Address,
rec = r
}
dgvCustomers.DataSource = records;
dgvCustomers.Columns["rec"].Visible = false;
now, this works wery well and the code is easy to type and read. Proble,, is this: The record bound to the DGV has no reference to the record in the db.Customers. Allso, the fields retreived fro, the select is standard STRINGs with no reference to the rec that allso is retreived.
This means that updating the rec wil not update the DGV. Updating the fields in the DGV wil not update the REC etc. etc.
One way to work around this that I use a lot is wrapping it all in a record class:
var records = from r in db.Customers
select r;
List<customerrecord> customers = new List<customerrecord>()
foreach(var r in records)
customers.Add(new CustomerRecord(r));
</customerrecord></customerrecord>
And this lets me control everything in the record since I can have properties in the record class.
Now, I have played a bit with EntityFrameWork and I get the feeling that this approach is kind of obsolete. That the EntityFramework contains all I nead to do this.
Allso, when searchning the MSDN I see that they allways use a BindingSource instead of binding the result directly to the DataSource. Should I use a BindingSource instead? And if so - Why?