NHibernate is a mature open-source object-relational mapper (ORM) for .NET, ported from Java's Hibernate. Like Entity Framework, it maps classes to database tables so you can work with objects instead of writing SQL for everything. Key concepts - ISessionFactory: an expensive, thread-safe object created once per application from the mapping configuration. - ISession: a lightweight unit of work, similar to EF's DbContext; open one per request or operation. - Mappings: XML (.hbm.xml), Fluent NHibernate, or NHibernate's built-in mapping-by-code. - Querying: LINQ provider, HQL (Hibernate Query Language), the Criteria and QueryOver APIs, and native SQL. - Features: lazy loading with proxies, first-level cache (per session), second-level cache (shared, with providers such as Redis), batching, multiple ID generators (HiLo is popular), and support for many databases. Example: using var session = sessionFactory.OpenSession(); using var tx = session.BeginTransaction(); var customer = session.Query<Customer>().Single(c => c.Email == email); customer.Rename("New Name"); tx.Commit(); // NHibernate detects the change and issues the UPDATE NHibernate vs Entity Framework Core - EF Core is Microsoft's ORM, the default in modern .NET, with strong tooling (migrations, scaffolding), active development and broad community examples. - NHibernate offers some advanced mapping and caching options and is found in many older enterprise applications, but its ecosystem is smaller. - Most new projects choose EF Core, or Dapper for lightweight SQL-first data access. How to answer if you have not used it: "I have heard of it and understand it is an ORM similar to EF Core, built around ISessionFactory and ISession. I have mainly worked with EF Core and Dapper, and the core ideas — unit of work, change tracking, lazy versus eager loading, N+1 problems — apply to NHibernate as well." That is honest and shows transferable knowledge.
Ravindra Wadile · · 0 likes