CSLA Framework

CSLA is a framework for building business applications. There are many great features built in CSLA: base classes for business objects and lists, business rules engine, authorization engine, remotable objects and many more. You can develop WindowsForms, WPF, Silverlight, even WindowsPhone7 applications using the same code base. However, all this functionality comes with one drawback, and that is complexity. Learning CSLA isn't the world's easiest thing to do.

Entity Framework

A lot of work needed when building a business application is writing the data access code. When working with CSLA you can choose data access technology as you wish. I started with low level classes like SqlCommand and SqlDataReader, later I used LinqToSql and when .Net Framework 4 was released, I started using Enity Framework. EF is not so great when you use it for the application business layer, but it’s a reasonable option for data access layer. EF has a nice model designer, model browser and an option to generate and refresh the model from the database. You can edit generated objects and EF preserves your changes when your refresh the model. EF supports inheritance and many-to-many relationships.
When you develop an application, common thing to start with is the database. There are other approaches, but many developers like the database first approach. Once you have created the database it’s very easy to create an EF model. Just import all the tables, views and stored procedures you need for your application. You can adjust the model in order to fit better to application needs by adding relations, inheritance or custom entities.


When I started using CSLA my main complaint was the amount of hand written code. CSLA is a framework and does not have fancy tools around it, so you have to do everything manually. And I mean everything. You have to write all the properties, data access code, factory methods, etc. This is fine if you have few classes in your project, but if you have a few hundred classes, there's a lot of work needed just for basic plumbing code. This code is easy to write, but time-consuming. If you write few thousand of lines of code you have a big chance to do something wrong. Also, CSLA changes constantly, and if you write all the code manually, when something changes you have to change all the code by hand or to stay at the same version of CSLA for the life of the project. Those are some of the reasons why I started this project in the first place.

Idea behind CslaExtension is that once you have created EF model that fits to the needs of your application, logical thing is to try to use that model to generate business layer classes.
This is accomplished with CslaExtension by adding custom properties to the EF designer, and with the T4 template which generates the code. Custom properties are added to different objects in the model: entities, properties, navigation properties and the model container. Using custom properties, you can define which classes and properties will be generated, parent-child relationships, access modifiers, namespaces and many more.
Good thing is that once you setup generation rules, they are preserved when refreshing the model from the database. Adding new properties to entities is a very simple task: add new column to the database table, refresh the model and code for that property is automatically generated. Generated classes are extensible by partial methods that are added to many places in the code. Also one can use events and override methods in order to customize generated classes. If that is not enough, you can write new CSLA class by hand and use entity framework for data acces.

Using CslaExtension, the time needed for initial development is much shorter. It’s also much easier to refactor code, add new objects and properties to the business layer. You can even customize T4 template in order to change code generation rules.

Last edited Oct 15, 2010 at 12:48 PM by jbudimir, version 4


No comments yet.