Improving nHibernate Data Access Layer Performance

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
{
   //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 update example. And there are about 400 entities that are interdependent. Is there a way to write unit test for this

+4
5

, .

, . ? , A B, , A, A. , , , B.

, A - , , . -, , , , , . (DTO) . , , -. DTO, , , , .

NHibernate, , , , .

, , , , . .

+3

1

  • lazy-loading
  • NhibernateDataContractSerializerSurrogate , WCF ( Allan )

SQL- .

, :

/ . /.

, / ( ), . - / ( ) .

2

SQL JOINs ? fetch = join fetch = select , .

3

, SQL, , . .

4

Nhibernate - , . WCF/Web Services ( db). , .

. .

, .

+3

, NHibernate ( 2.1.2, AFAIK), - 3.0. , , , . , NHibernate API , .

, :

, , , - , , !

NHibernate - ORM , , . .

:

  • Timestamps

:

  • : ISession. .
  • : ISessionFactory. .

, , . nhibernate.info , StackOverflow varios .

:

  • , ISession ISessionFactory
  • ( )

, , , - , , . . , .

+2

, NHibernate Profiler? ( 30- )

NHibernate Profiler - , NHibernate. , NHibernate . , . , .

+1

NHibernate....

0

All Articles