开发者

WCF+NHibernate+LazyLoading

I'm having issues transferring lazy loaded data over the wire using WCF and NHibernate. I've more than 5,000,000 records all together.

The application is multi-tier, uses MVVM and works as: WCF (net.tcp Binding) --> Data Access Layer --> Business Layer --> UI.

There is no issue with WCF or NHibernate. The mappings are proper and it finely lazy loads the data at WCF end.

The issue is while sending it to the client across network. The lazy loaded data starts expanding to actual, which takes minimum 30 minutes.

Is it possible to stop this expansion?

Here is the class architecture:

class A

{

  //properties

   IList<B> list;

}



class B

{

  //properties

   IList<C> c_list;

   IList<D> d_list;

   IList<E> e_list;

   IList<F> f_list;

   IList<G> g_list;

}



class C

{

  //properties

   IList<D> d_list;

   IList<E> e_list;

   IList<F> f_list;

   IList<G> g_list;

}


class D

{

  //prope开发者_Python百科rties

}

class E

{

  //properties

}



class F

{

  //properties

}



class G

{

  //properties

}


Turn off lazy loading or use DTOs!!! That is the solution. Transferring 5M records looks like nonsense and if your collections are lazy loaded initial serialization can trigger several hundred thousands database selects. Also if each record has only 1B you will transfer 5MB - I doubt that record has 1B so we can talk about transferring tens MB.


Recommended approach is not to expose your domain model via WCF. You should send DTO's over network. In this case you will be able to control lazy loading on server side and design it properly. Also I recommend to use NHibernate Profiler. And 5 millions records is huge amount of data - consider to implement paging on server side

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜