Answered by:
Live data - Update from database - Entity Framework 4.2

Question
-
Hi,
I'm using the Entity Framework 4.2 and the dbContext.
I have a datagrid (wpf) that display data from a table in my database.
When a change is done in the database, how can I update my datagrid without any click ?
Thank you
Friday, January 27, 2012 4:50 PM
Answers
-
From what I know the DbContext API has only calls to update individual entities - one by one - so you will have to iterate over the entities yourself; and then you still don't know which ones have been deleted in the DB...
Generally, if you consider all possibilities and special cases of references between entities, synchronizing the context with the DB can get very complicated which makes a general/automated approach rather difficult. You can read about the caveats and a decent workaround for simple cases here:
http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/2cbe61f3-1e26-49d5-9ce9-82ae48b1cfbb- Edited by Andreas Steidle Saturday, January 28, 2012 9:00 AM
- Marked as answer by Alan_chen Thursday, February 9, 2012 8:13 AM
Saturday, January 28, 2012 8:40 AM
All replies
-
From what I know the DbContext API has only calls to update individual entities - one by one - so you will have to iterate over the entities yourself; and then you still don't know which ones have been deleted in the DB...
Generally, if you consider all possibilities and special cases of references between entities, synchronizing the context with the DB can get very complicated which makes a general/automated approach rather difficult. You can read about the caveats and a decent workaround for simple cases here:
http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/2cbe61f3-1e26-49d5-9ce9-82ae48b1cfbb- Edited by Andreas Steidle Saturday, January 28, 2012 9:00 AM
- Marked as answer by Alan_chen Thursday, February 9, 2012 8:13 AM
Saturday, January 28, 2012 8:40 AM -
Thanks and what do you think about SQLDependency ?Monday, January 30, 2012 1:21 PM
-
Hi gazier20,
You can refer this link here: http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/c8f63304-bde1-4bb9-9682-2468750f9ff6
Have a nice day.
Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, February 6, 2012 2:52 AM