views:

655

answers:

1

One of my chief annoyances with Linq to SQL in WinForms (and I daresay WPF) is the lack of support for long running datacontexts see here.

The problem is that you can't get updates from the database, you only ever get the same old records until you throw the datacontext away. This is fine for a web app when the page is only alive for milliseconds but not so good in a winforms app with multiple bound controls all stuck to the old datacontext and sitting on the users desktop.

My question is does EF still have this limitation or can you get updated records from EF without throwing away the object context?

+2  A: 

You can use the ObjectContext.Refresh method to update an existing context.

Andrew Peters
Thanks. Actually you can use db.Refresh(System.Data.Linq.RefreshMode.KeepChanges, myObjectsCollection) in Linq to SQL but it issues a separate select query for each individual object that needs to be refreshed. Do you happen to know if ObjectContext.Refresh is more efficient?
Christopher Edwards
Yes, it does batch updates by entity set.
Andrew Peters