I am working on improving the performance of the DataAccess layer of an existing Asp.Net web application. Scenarios
- This is a web application in Asp.Net.
- The DataAccess layer is created using NHibernate 1.2 and is displayed as a WCF service.
- The Entity class is labeled DataContract.
- Lazy loading is not used, and because of the impatient binding of relations in memory, a huge number of database objects are not loaded. The number of database calls is also large. For example, I profiled the application using NHProfiler, and there were about 50 + sql calls to load one of the Entity objects using the primary key.
- I also can’t change the code much, like its existing application that does not have NUnit test cases at all.
Can I get some suggestions here?
EDIT 1: I tried to use Lazy loading, but the problem is that since Entity is also used as a DataContract, it starts lazy loading during Serialization. Using DTO objects is an option, but this is a huge change since none of the Entities is huge. Without test cases, this will require a huge amount of manual testing effort.
EDIT 2: The project was written long ago, without the flexibility to write unit tests. For example, the object itself contains a CRUD operation and uses an NHibernate session.
class SampleEntity : ICrudOperation
{
public IList<SampleEntity> Update()
{
ISession session = GetSessionFromSomewhere();
session.Update(this);
}
}
This is just an update example. And there are about 400 entities that are interdependent. Is there a way to write unit test for this