Question

I am working on a component factory system where ObjectContexts are automatically created depending upon some configuration rules. Each time a method is called, the component factory decides where to create an ObjectContext/Transaction scope, etc.

I was able to handle the ObjectContext creation and disposal in most cases. But when a method recursivelly call itself, I am creating an ObjectContext each time the method is called. It would be something like this:

using (MyEntities entitityContext = new MyEntities())
{
    // do some code here
    entitityContext.SaveChanges();

    using (MyEntities anotherEntitityContext = new MyEntities())
    {
        // do some other code here
        anotherEntitityContext.SaveChanges();
    }
}

How do the EntityFramework deals with it? Does the second ObjectContext is the same as the first one? If not, how could I manage to the second ObjectContext be the "same" reference to the first one with the same ''new ObjectContext()'' construction?

I know that on aligned TransactionScopes joins each other in a sequence, depending upon the Transaction configurations. I want the ObjectContext to have the same behavior. Is this possible without having any reference to the parent ObjectContext?

Was it helpful?

Solution

I found out that Phil Soady is correct. I found another way of using ObjectContexts without having to create multiple objects. Thanks for your comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top