1. Introduction to EntityManager
  2. Create Update Delete
  3. Special Functions
  4. Creating your own Repository

What is EntityManager ? As the name implies, its a Runtime object that manages the life cycle of entities that are persisted and/or loaded from the Rapid Runtime Engine . Most people call this concept Repository Pattern, like a Singleton which takes care of activating , persivating , deletion and query ability of entities configured for the framework.

The EntityManager is more than a Repositories of entities it actualy gives you more sophisticated features for free. If you are not satisfied with the *EntityManager , you can abstract this object by inheriting from it, the child class may now be your repository.

In this section, i will be showing you what you can do with the EntityMnager , how you can inherit from it and create your own Repository from it. How it handles entity life cycle, the do's and dont's.

1. Instantiating The EntityManager
using ( EntityManager manager = new EntityManager() )
{
    manager.OpenDatabaseSession();
}
Code Review
The EntityManager implements the IDisposable interface , the above code will get the current Configuration which you must have set. Go to Setting Up The Configuration if you need to catch-up on that area.

After instantiation, you will call the OpenDatabaseSession method explicity, by doing so, the underlying provider will open a database connection and activates a transaction under the hood.

Notice that the above EntityManager is instantiated within the using statement, the closing braces of the using statement will commit the operations you made within the context of the using statement.

2. Example of Getting All Authors with the EntityManager
using ( EntityManager manager = new EntityManager() )
{
    manager.OpenDatabaseSession();

    foreach( var author1 in manager.GetAll<Author>( ) )
    {
        Console.WriteLine( " {0} {1} " , author1.Aufname , author1.Aulname ); 
    }
}

Generated Results
GetAllResults.JPG

Last edited Feb 8, 2010 at 5:25 PM by udayshanbhag, version 13

Comments

No comments yet.