This has been bugging me for a while, not sure how it works.
When working with an Entity Framework, suppose you create an instance of your context, run a query on it, grab an object from the query, pass that object somewhere else, then let the context go out of scope.
What happens to the retrieved object? Does it become detached? What if I modify it and want to write back to DB?
Here's a sample snippet code to explain what I mean:
(suppose MyObject is a class created by the Entity Framework designer to represent a particular DB table)
public class foo
{
public MyObject currentMyObject;
public void GetMyObject()
{
using (MyEFEntitiescontext = new MyEFEntities())
{
currentMyObject = context.MyObjects.FirstOrDefault();
}
}
public void doSomething()
{
}
}
(note - I just threw the code together here, not in VS, so please ignore syntax errors :) )
If I run GetMyObject() first, and then run the function doSomething() second, what does the inside of that function see? How can it send changes made to the current object back to the DB?
Thanks,
Juliean.