This forum is used by the Opf3 developers to announce new features or to discuss with you about ideas on new features.
 | |
| | The next version will also include an ObjectContextFactory. You can use it by calling the static Factory property of the ObjectContext:
// Get an ObjectContext instance. ObjectContext context = ObjectContext.Factory.GetContext();
But how to set the thing up? The ObjectContextFactory needs a Policy to work properly. Opf3 comes already with a per thread policy (which creates a new ObjectContext instance for each thread) and a single call policy (which creates a new ObjectContext instance on each call). The first one is very useful, if you create a Windows application. The second one is useful, if you create an ASP.NET website.
ObjectContext.Factory.Policy = new SingleCallObjectContextFactoryPolicy(delegate() { MsSqlStorage storage = new MsSqlStorage("... connection string ..."); ObjectContext ctx = new ObjectContext(storage);
return ctx; });
This piece of code sets the factory up to create a new ObjectContext instance on each call. Setting it up to create a new ObjectContext instance for each thread looks like this:
ObjectContext.Factory.Policy = new PerThreadObjectContextFactoryPolicy(delegate() { MsSqlStorage storage = new MsSqlStorage("... connection string ..."); ObjectContext ctx = new ObjectContext(storage);
return ctx; });
Christian
|