📜 ⬆️ ⬇️

Basics of NHibernate (easy tutorial)

Translation of the NHibernate Basics article from codeproject.com.

Conducting


Nhibernate is a solution for Object Realization Map for the .NET platform. This framework allows mapping of Object Oriented Models to traditional databases. Its main advantage is mapping of .Net classes to database tables and from CLR data types to SQL types.

As indicated in the title of our article, we will look at: How to load business objects from the database and save the modified objects back to the database.

Training


The demo application will show us how the easiest way to install and use NHibernate. The application creates an Employee object and stores it in the Employee table. It also does some operations such as retrieving and deleting Employee objects. This application was created using NHibernate 3.2.0, VS 2010 and SQL Server 2008.
')

Code use


Database

First we set up the database. Use SQL Server Managment Strudio to create a database and work with it. As shown below create a new database, and name it NHibernateBasics.



Then add the Employee table with two columns; ID and NAME.



The ID column must be the primary key, and must be auto-increment. Be sure to include the Identity Specification in the column properties.



Business Objects

DB is ready for demonstration. Now we start Studio and we create the new WindowsFormApplication application, we will name the project NhibernateBasics.
Add a new class, name it Employee.cs, and paste in the following code.

namespace NHibernateBasics { public class Employee { public virtual int ID { get; set; } public virtual string Name { get; set; } } } 

One of the strengths of Nhibernate is that it does not need special interfaces for business classes. These objects are independent of the mechanism for loading and saving data. However, it is required that class properties be described as virtual, so that they can create Proxi.

XML file mapping

Due to the lack of a specific code for hibernation, someone must take responsibility for the transmission from the database to the business objects and back. This translation can be performed by linking through an XML file or by linking attributes to classes and properties.
In our demo application, we used a mapping file to avoid cluttering up a business object class.

Add a new XML file to the project. The XML file will be used as a mapping file. The file name must be Employee.hbm.xml. Class file
 .cs 
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
 .cs 
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
 .cs 
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }
:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?

.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }
:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?

.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
 .cs 
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
 .cs 
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
 .cs 
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
 .cs 
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?
.cs
.hbm.xml
.

.

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateBasics" assembly="NHibernateBasics"> <class name="Employee" table="Employee"> <id name="ID" column="ID"> <generator class="identity"/> </id> <property name="Name" column="Name" /> </class> </hibernate-mapping>

XML Build Action = Embedded Resource.





(app.config).
.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="query.substitutions">hqlFunction=SQLFUNC</property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=(Local)\SQL2008;Initial Catalog=NHibernateBasics; Integrated Security=True</property> <property name="show_sql">true</property> <mapping assembly="NHibernateBasics" /> </session-factory> </hibernate-configuration> </configuration>
Connection-string . CATALOG=, NHibernateBasics. mapping assembly=, NHibernateBasics.



. , .

:

using(mySession.BeginTransaction()) { // Insert two employees in Database mySession.Save(myInitialObjects[0]); mySession.Save(myInitialObjects[1]); mySession.Transaction.Commit(); }

:

using(mySession.BeginTransaction()) { // ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); for (int i = 0; i < myFinalObjects.Length; i++) { myFinalObjects[i] = list[i]; MessageBox.Show("ID: " + myFinalObjects[i].ID + " Name: " + myFinalObjects[i].Name); } mySession.Transaction.Commit(); }
:

StringBuilder messageString = new StringBuilder(); // for (int i = 0; i < 2; i++) { messageString.AppendLine("Comparing Class Object " + myInitialObjects[i].Name + " and DB Object " + myFinalObjects[i].Name + ". Result = " + myInitialObjects[i].Equals(myFinalObjects[i]).ToString()); } MessageBox.Show(messageString.ToString());
:

using (mySession.BeginTransaction()) { // Delete one object from Database mySession.Delete(myInitialObjects[0]); mySession.Transaction.Commit(); }
:

using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria<employee>(); IList<employee> list = criteria.List<employee>(); StringBuilder messageString = new StringBuilder(); // Load and display the data foreach (Employee employee in list) { messageString.AppendLine("ID: " + employee.ID + " Name: " + employee.Name); } MessageBox.Show(messageString.ToString()); }
NHibernte . , .

Nhibernate.

Happy coding /////

: NHibernateBasics.zip

Nhiberante. Nhibernate ?

Source: https://habr.com/ru/post/267505/


All Articles