Click here to Skip to main content
13,457,971 members
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 17 Sep 2008

Web-Application Framework - Catharsis - part V. - adding new Entity

, 1 Oct 2008
Rate this:
Please Sign up or sign in to vote.
Catharsis web-app framework - adding new Entity (enter into Catharsis)

Enter into Catharsis - adding new Entity

This article is next step in Catharsis documented tutorial. Catharsis is web-application framework gathering best-practices, using ASP.NET MVC (preview 5), NHibernate 2.0. All needed source code you can find on



New solution VI CatharsisArchitectureXI (Controller layer - undone)  

II Home page observationVII Entity layer XII (UI Web layer - undone) 

III Roles and usersVIII Data layer XIII Tracking, PAX design pattern

IV Localization, translationsIX Business layerXIV Catharsis Dependency Injection (DI, IoC) 

Enter into Catharsis, new EntityModel layer  XV (Code Lists - undone)    

Adding new Entity into solution 

At this chapter You will Enter into Catharsis! In any meaning that sentence can have.

Prerequisites: Catharsis.Guidance 0.8.7; You have installed Catharsis.Guidance (Registered the source code, or installed provided Setup); You have created new Solution (using Guidance) or opened the Example solution; You have SQL Server 2005, well you can (due to NHibernate) have any storage!!! but for our tutorial, the scripts and stuff will be SQL Server 2005 oriented.

I suggest you follow this tutorial (this chapter) exactly! Once is enough - to catch the essence of Catharsis. You‘ll see. 


Object Person

Let’s say, we need the Person object for our application. In the future phases of application development this object can hold information for Supplier’s ContactPerson, or for application User, or for Employee

At the very beginning we will need three properties. 1) Code, which will be unique for every person 2) FirstName and 3) SecondName (not so brainy, but clear enough).

What do we need next? Create objects (classes) which will allow us to handle object Person. To create new Persons, change them, display them in the list, sort them, search … get access to right users, apply business rules …

Table Person

To store Person in DB we’ll create table:

(SQL Server snapshot)


CREATE TABLE [dbo].[Person](
   [PersonId] [int] IDENTITY(1,1) NOT NULL
 , [Code] [nchar](150) NOT NULL,
 , [FirstName] [nvarchar](250) NOT NULL,
 , [SecondName] [nvarchar](250) NOT NULL,
    [PersonId] ASC

Notes to table Person

Table needs primary key, in our case PersonId which is in our case of type int. Catharsis is based on integer keys (so if you want to change this behavior for your application, find and change settings in a core libraries Catharsis.Entity, Catharsis.Data).

Table should have its PersonId set to auto identity, which allows us to let that job on NHibernate and database. This key is needed for relations, foreign-keys, indexes… on a DB side. Application will use it as the ‘object built-in property ID’, mainly on UI as an identifier (the <select ...><option value="entity.ID"...> is good example).

Every POCO entity in Catharsis framework must be derived from class public abstract class PersistentObjectWithTypedId<int> from namespace Catharsis.Entity.PersistentObjects. As you will see in a future chapters there are prepared to base classes for you in ‘Firm.Product.Entity’ library Persistent and Tracked.

The last thing I would like to mention is the ‘NOT Null’ constraint. I strongly suggest you do not create NULL columns in your DB. There should be always any value provided by user (except of cases like FireDate of Employee, which is really and maybe the only good example of using Null). It could lead to a good discussion, but at this point the suggestion is enough.


Well, we have table for our Person. And we have opened Catharsis solution and installed Catharsis .Guidance (see previous chapters)

Select your ‘Firm.Product.Entity’ project. Create new folder named for example ‘People’. Right click on this folder and you should see a menu item

(Re) Create COMPLETE infrastructure.


If this menu item is missing then you have to switch on the guidance (all needed steps are shown in the next picture)


(Re) Create COMPLETE infrastructure

Click this menu item and the wizard screen will appear:


Class Name will be Person. The next three inputs can be filled with properties. The first (if provided) is returned by the Entity method GetDomainObjectSignature(), which is responsible for distinguishing among instances. Fill in Code, FirstName and SecondName.

Because you have clicked on an ‘People’ folder, its name is provided as namespace. On the next page are checkboxes which now must remain unchecked. Just click Finish. And the Catharsis will be coming.

Adding few features

Catharsis.Guidance just have created many classes into every layer. You can (should) build the solution, which will fail because of missing Controller name ‘Person’.

Controller Person const

Open ‘Firm.Product.Common’ project, folder Constants. Add into the file ‘Str.Controllers.cs’ public

Person = "Person"

ReBuild solution, no error should be reported. The last think we have to do is add Person to Navigation links.


Naviagtion to Person

In the ‘Firm.Product.Business’ project open folder AopFilters and select class NavigationAttribute.cs. This is an AOP filter-attribute, which (at current version of Catharsis) very simply sets navigation-links dependently on the user’s CurrentRole.

Just imagine: You create smart xml file with navigation. Which user can from which controller or action navigate to which links, dependently on CurrentRole. You will provide an Xml Navigation Reader on that attribute, and application as whole gets a really strong work-flow! One Place!)


The last think is assure, that you as a user, have been added to application, and that you have been granted for roles Viewer and RegisteredUser. Catharsis will help us in the runtime …

Do not hesitate and press F5, just to start debug…

Enter into Catharsis

Look, observe and test what have changed in our application. New navigation is available (for RegisteredUser and Viewer roles). You can add, update, list, sort, search and delete Person entities.

The only needed tasks was: Create Table, run the Catharsis.Guidance wizard to create all needed classes, Add constant to Controller names and grant access to this new area-entity-controller  

You'll like it...

Enjoy Catharsis 
Radim Köhler


All needed source code you can find on




This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Radim Köhler
Web Developer
Czech Republic Czech Republic
Web developer since 2002, .NET since 2005

Competition is as important as Cooperation.


You may also be interested in...

Comments and Discussions

QuestionPlease update the tutorial with the new Catharsis version Pin
thichmynhan4-Jan-09 16:39
memberthichmynhan4-Jan-09 16:39 
AnswerRe: Please update the tutorial with the new Catharsis version Pin
Radim Köhler5-Jan-09 7:31
memberRadim Köhler5-Jan-09 7:31 
General'Users' link causes 'Object reference not set to an instance of an object' Pin
wadep8-Oct-08 13:01
memberwadep8-Oct-08 13:01 
GeneralRe: 'Users' link causes 'Object reference not set to an instance of an object' Pin
Radim Köhler8-Oct-08 13:28
memberRadim Köhler8-Oct-08 13:28 
GeneralRe: 'Users' link causes 'Object reference not set to an instance of an object' Pin
wadep8-Oct-08 23:09
memberwadep8-Oct-08 23:09 
GeneralRe: 'Users' link causes 'Object reference not set to an instance of an object' Pin
Radim Köhler8-Oct-08 23:20
memberRadim Köhler8-Oct-08 23:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180323.1 | Last Updated 1 Oct 2008
Article Copyright 2008 by Radim Köhler
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid