Saturday, May 14, 2005

[Opf3] Set up the framework

Since everything needs to start somehow, also Opf3 needs to be initialized. Some ORM make it really hard to set them up. For Opf3 we tried to make this as easy and short possible. The following lines set up the framework (which includes also an instance of the Md5ConcurrencyManager to manage simultaneous access to the storage).

ObjectContext context = new ObjectContext(new AccessStorage(@"C:\", "northwind.mdb"));
context.ConcurrencyManager = new Md5ConcurrencyManager();

The code creates an instance of the ObjectContext. The ObjectContext is the main class in Opf3. It allows you to load objects from storage and store them back there.

The framework is now fully set up!

The following line loads an User object from the storage (the database):

User user = context.GetObject<User>("UserName = {0}", "Some guy's name");

This sample specifies also a name of the user that is loaded. The name is "Some guy's name". Opf3 supports IDbParameter by using the syntax of string.Format, which means {0} for the first parameter, {1} for the second, etc... For more information about the User object look here.


Post a Comment

<< Home