Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialize nhibernate entity to json error: Cannot serialize a Session while connected

I'm trying to serialize an nhibernate entity in to json but I always get this error saying Cannot serialize a Session while connected? Does it has something to do with nhibernate proxy?

like image 375
ryudice Avatar asked May 01 '11 22:05

ryudice


1 Answers

Yes, this is related to lazy loading. You will need to configure NHibernate to eagerly fetch associations if you want to be able to JSON serialize it. But I would recommend you using view models instead. Ayende Rahien blogged about this issue.

like image 113
Darin Dimitrov Avatar answered Oct 16 '22 13:10

Darin Dimitrov