NHibernate is an object-relational mapping (ORM) framework for the .NET platform. It provides a mapping between relational databases and application objects to enable faster development and easier maintenance of applications.
Code Example:
The following code example shows how to use NHibernate to save and retrieve data from a database:
// Create a new customer var customer = new Customer { FirstName = "John", LastName = "Smith", Email = "[email protected]" };
// Save the customer to the database using (var session = sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { session.Save(customer); transaction.Commit(); } }
// Retrieve the customer from the database using (var session = sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { var retrievedCustomer = session.Get(customer.Id); Console.WriteLine("Customer name: " + retrievedCustomer.FirstName + " " + retrievedCustomer.LastName); transaction.Commit(); } }
This example uses the NHibernate package library, which can be installed via NuGet.
Summary:
NHibernate is an ORM framework for .NET that provides a mapping between relational databases and application objects. It's useful for saving and retrieving data from a database. The code example demonstrates how to create a new customer, save it to the database, and retrieve it from the database using NHibernate. The example uses the NHibernate package library, which is available via NuGet.
C# (CSharp) NHibernate - 34 examples found. These are the top rated real world C# (CSharp) examples of NHibernate extracted from open source projects. You can rate examples to help us improve the quality of examples.