The first part of making rapid entity framework work for your project is through Rapid configuration. Rapid entity framework makes use of code based configuration (Future releases will make use of XML configuration), and this will be used by the Rapid run time engine to ensure your application run according to the configuration set. The configuration is initialized only once in an application life time, so its best to place the configuration in class or method that is called once in application life time. Most web developers makes use of the global.asax . and most windows based application choose to use the startup class (Program).

Two Types of configuration
There are two types of configurations depending on your project.
  1. Web Configuration : This type of configuration is mostly suitable for projects hosted on a web server like IIS. Examples are ASP.NET application, Web Services and Windows Communication Foundation (WCF). You will use the WebConfigurationFactory class to configure your web based projects with rapid.
  2. Desktop Based Configuration : For applications that runs on the local system of a user, you will need to use the ConfigurationFactory class to configure your desktop based (Windows service, console and Windows Forms application).

Note There is no big difference between both configurations, the syntax are the same, you are just using different factories.

Both configuration types inherits from ConfigurationBase class. The following example will use the ConfigurationFactory class against the good old Pubs database.

            1.  string connection = "Data Source=localhost;Initial Catalog=pubs;Integrated Security=True";
            2.  IConfiguration configuration = ConfigurationFactory.GetInstance( connection );
            3. configuration.ProviderDialect = ProviderDialect.SqlProvider;
            4. configuration.CacheSettings( 20 , 200 );
            5. configuration.Compile( "RapidPubs" );

The code above is pretty simple to digest. The following is the code walkthrough line by line.
  1. Connection string : The connection string to the database in question.
  2. * IConfiguration configuration = ConfigurationFactory.GetInstance( connection );* This snippet use the factory ConfigurationFactory to create an instance for the configuration interface which allows you to set all the runtime behaviors.
  3. Line 3 sets the ProviderDialect , for this example the SqlProvider which is any microsoft sql database products will be used.
  4. CacheSettings : Rapid encourages you to set the caching strategies, the first parameter is the eviction minute (Time that an entity can live in the cache before its eviction). The second parameter is number of entities that can live at a time in the cache. Rapid has an internal garbage collector that monitors the cache and removes over stayers, it can also swap places when the cache is full.
  5. Line 5 compiles the .dlls that contains the entities up front. This is a good feature because metadata details are extracted once in an application life time using the compile method of the configuration class. The parameter is the fully qualified name of the dll that contains the entities.

Setting the Transaction Scope/Context Scope
There are situations you want entity changes to span multiple instances of the entity managers. we have added a feature in the configuration sections where you can set lifetime of an entity. This means, an entity changed by a EntityManager can be undo by another entity manager.

The enum is called TransactionCacheBoundary which needs to be set:

TransactionCacheBoundary.CrossBoundary : Means entities change tracking lifetime will span multiple transaction boundary, a single entity changes can be undone or persisted by multiple entity managers.
TransactionCacheBoundary.EntityManagerScope : The context/entity manager that creates this entity only have access to its changes. No other entity manager knows about the change state of this entity, so you cannot undo transactional changes.


After configuring your application for rapid, you will then need to starting using the fine grained features provided to you by Rapid Entity Framework.

Last edited Mar 1, 2011 at 10:51 AM by ahmedsalako, version 14


No comments yet.