Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
EF4 - Multiuser app - Deleted children
Message
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01549474
Message ID:
01549513
Views:
85
This message has been marked as the solution to the initial question of the thread.
Entity framework internally caches entities it retrieves in its object graph, which means you won't see changes... until you dump the context or explicitly reload.

There are a couple of ways around this.

I see you're using MergeOption.OverwriteChanges which *should* actually be enough to force the query to be re-loaded. But apparently that's not working for you?

The easiest is probably to make sure you always query on a new DbConecxt instance. Make sure you recreate a new context rather than re-using an existing context.

Another option is to use context.Entry(entity).Reload() which forces an individual entity to be reloaded from disk.

Depending on your scenario the latter can be more efficient as it's actually just requerying a single record not the whole set.

+++ Rick ---

>I am currently testing an application using EF4.3 containing pre-compiled queries.
>
>
>                    mqryClientByID = Function(ctx As FGLMainDataEntities, pID As Integer)
>                                         Return (ctx.Clients.
>                                                 Include("EMails").
>                                                 Where("it.ID = " + pID.ToString()
>                                                ).Execute(MergeOption.OverwriteChanges).SingleOrDefault())
>                                     End Function
>
>
>This basically get a client's data and his related email addresses.
>
>I just found that if I modify the emails directly in SSMS (simulating another user modifying records), I can see the modification whenever I re-execute my query with:
>
>
>Dim currentClient = mqryClientByID.Invoke(mobjContext, pID)
>
>
>But if I delete email addresses related to a client and I reload the client, the row is still shown in the grid.
>
>How can I tell EF to refresh data for real?
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform