I am working on improving the performance of DataAccess Layer of an existing Asp.Net Web Application. The scenerios are.
- Its a web based application in Asp.Net.
- DataAccess layer is built using NHibernate 1.2 and exposed as WCF Service.
- The Entity class is marked with DataContract.
- Lazy loading is not used and because of the eager-fetching of the relations there is huge no of database objects are loaded in the memory. No of hits to the database is also high. For example I profiled the application using NHProfiler and there were about 50+ sql calls to load one of the Entity object using the primary key.
- I also can not change code much as its an existing live application with no NUnit test cases at all.
Please can I get some suggestions here?
EDIT 1: I have tried using Lazy loading but the issue is that since the Entity is also used as DataContract it triggers the lazy loading during Serialization. Using a DTO Objects is an option but that is a huge change as no of Entities are huge. Without the Test cases this will require a huge amount of manual Testing effort.
EDIT 2: The project was written long back with no flexibility to write unit tests. E.g The entity itself contains the CRUD operation and uses NHibernate Session.
class SampleEntity : ICrudOperation
{
//fields and properties
public IList<SampleEntity> Update()
{
//perform business logic (which can be huge and call the ICrudOperation of
//other entities
ISession session = GetSessionFromSomewhere();
session.Update(this);
}
}
This is just an example for Update. And there are around 400 Entities which are interdependent. Is there a way to write unit test for this