Here's the scenario, i have a website, which in a single HTTP request (HTTP POST), i need to do the following:
Behind the scenes, 2) involves database-side triggers that affects data on "Tag".
So when i do 3), EF is pulling the same copy of the object from step 1), since it's in the graph/internal memory (e.g same connection/context)
I need a "fresh" copy of the object.
In the past, i've used Detach
, then i perform an EF query and the latest object in fetched from the DB.
But i don't have access to the object here per-se (i have a DTO, which is returning from my repository), so i don't have anything to pass to the Detach
method.
Is there any way to say:
var fresh = db.Tags.Find(1, ignoreGraph: true)
Or is there another alternative?
As mentioned, i'm on Entity Framework 4.1, C# 4 (and ASP.NET MVC 3)
The only solution i can see right now is to pass a querystring parameter to the next page, which then grabs the fresh copy (since it's a new context, new graph, etc).
DbSet in Entity Framework 6. The DbSet class represents an entity set that can be used for create, read, update, and delete operations. The context class (derived from DbContext ) must include the DbSet type properties for the entities which map to database tables and views.
Found my answer, i think:
Context.Entry<T>(entity).Reload()
Trying now...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With