An example as shown below is that

1. scope1 will create the initial object context of dbEntities.

2. scope2 will use scope1 object context as the objectcontext is of the same type of dbEntities.

3. scope3 will create its own object context, which can only be used in scope3

4. scope4 is of a different objectcontext type, so a new objectcontext is created of type db2Entities.

5. scope 5 will use scope1 object context as scope 3 is only for scope3 and cannot be used inside any other scope.

using (ObjectContextScope scope1 = new ObjectContextScope())
{
using (ObjectContextScope scope2 = new ObjectContextScope())
{
using (ObjectContextScope scope3 = new ObjectContextScope
(ObjectContextScopeOption.RequiresNew))
{
using (ObjectContextScope scope4 = new ObjectContextScope
(ObjectContextScopeOption.Required))
{
}

using (ObjectContextScope scope5 = new ObjectContextScope
(ObjectContextScopeOption.RequiresNew))
{

}
}
}
}

Last edited Jan 28, 2010 at 10:07 AM by Jetski5822, version 1

Comments

No comments yet.