views:

1056

answers:

2

I'm starting on a small windows forms project that makes extensive use of editable grids. I want to use Linq to Entities, but while it's trivial to bind a grid to the Linq query it's read-only. I couldn't figure out a good way to have an editable grid that auto-updates the database. (I hacked a work-around where I copy the data into a dataset for display/update and translate back... ugly!)

So for now I've decided to forget Linq to Entities and use the old table adapter/dataset method from 2.0.

Is there a compelling reason why I should use Linq to Entities instead? Is there a way to do editable grids that I just missed?

+2  A: 

You can just bind an entity collection returned by a query to an control and this will allow editing the bound entities. May be you should insert a BindingSource between collection and control, but that depends. If you call SaveChanges() on the object context the changes are persisted to the database. So data binding with the Entity Framework definitly works.

Daniel Brückner
For some reason why I try that I get a read-only grid. Perhaps it's the infragistics grid control I'm using?
Jeff
I cannot tell if this is an issue with that control. Just try it with a DataGridView - this works without any tricks.
Daniel Brückner
Thanks. I found I was binding to a query result, not the entity itself. Thus the read only. I'll give linq another shot.
Jeff
I was able to successfully bind the entity to a grid with read/write. However, the grid then fills in with all the data. Linq allows queries, but the results are separate from the entity. Binding to the query results is thus read-only. An unfiltered grid isn't very usable. :-(
Jeff
+1  A: 

Found the solution: use lamda expressions to filter the entity, then bind directly to the entity. Works great.

Jeff