In NHibernate, a SessionFactory is considered a heavy object, and it is assumed that a SessionFactory must be created once during the life of the application. However, as soon as we get a call to SessionFactory, we call open () on it before performing any operation on the DB.
In EntityFramework, we need to create an ObjectContext object each time before performing any operation with the main storage. There is no discovery per se in the case of EF.
My questions:
Creating context in EF is similar to calling Open () in SessionFactory in NHibernate?
Or should I create an ObjectContext once during the life of the application and share it?
Update:
I found the following ObjectContext lifecycle management link. However, in this link, the author mentions:
http://dotnetslackers.com/articles/ado_net/Managing-Entity-Framework-ObjectContext-lifespan-and-scope-in-n-layered-ASP-NET-applications.aspx#1390
However, you should not use a static ObjectContext in an ASP.NET application, since static elements have a lifetime that exceeds the lifetime of a single HTTP request. In fact, they are associated with the life of the AppDomain, which can be minutes or hours. In fact, the static members of a class in ASP.NET are even shared between multiple threads and users expression. Using the same Instance of an ObjectContext from within multiple threads at the same time can cause serious problems.
NHibernate . SessionFactory , .
, Entity Framework?