Click here to Skip to main content
15,892,537 members
Articles / Programming Languages / SQL

NHibernate Basics

Rate me:
Please Sign up or sign in to vote.
4.73/5 (31 votes)
10 Jul 2011CPOL3 min read 136.4K   5.3K   44  
ABCs of NHibernate, a small application to demonstrate save and load of objects to and from Database.
namespace NHibernateBasics
{
    partial class FormDemo
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
                mySession.Close();
                mySession.Dispose();
                mySessionFactory.Close();
                mySessionFactory.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.myButtonConfigure = new System.Windows.Forms.Button();
            this.myButtonClearDB = new System.Windows.Forms.Button();
            this.myButtonInsertData = new System.Windows.Forms.Button();
            this.myButtonRetrieveData = new System.Windows.Forms.Button();
            this.myButtonCompare = new System.Windows.Forms.Button();
            this.myButtonDelete = new System.Windows.Forms.Button();
            this.myButtonDisplay = new System.Windows.Forms.Button();
            this.myLabelStatus = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // myButtonConfigure
            // 
            this.myButtonConfigure.Location = new System.Drawing.Point(13, 11);
            this.myButtonConfigure.Name = "myButtonConfigure";
            this.myButtonConfigure.Size = new System.Drawing.Size(196, 41);
            this.myButtonConfigure.TabIndex = 1;
            this.myButtonConfigure.Text = "Configure";
            this.myButtonConfigure.UseVisualStyleBackColor = true;
            this.myButtonConfigure.Click += new System.EventHandler(this.myButtonConfigure_Click);
            // 
            // myButtonClearDB
            // 
            this.myButtonClearDB.Enabled = false;
            this.myButtonClearDB.Location = new System.Drawing.Point(13, 58);
            this.myButtonClearDB.Name = "myButtonClearDB";
            this.myButtonClearDB.Size = new System.Drawing.Size(196, 42);
            this.myButtonClearDB.TabIndex = 2;
            this.myButtonClearDB.Text = "Clear Database";
            this.myButtonClearDB.UseVisualStyleBackColor = true;
            this.myButtonClearDB.Click += new System.EventHandler(this.myButtonClearDB_Click);
            // 
            // myButtonInsertData
            // 
            this.myButtonInsertData.Enabled = false;
            this.myButtonInsertData.Location = new System.Drawing.Point(13, 106);
            this.myButtonInsertData.Name = "myButtonInsertData";
            this.myButtonInsertData.Size = new System.Drawing.Size(196, 42);
            this.myButtonInsertData.TabIndex = 3;
            this.myButtonInsertData.Text = "Save in Database\r\n<2 Employees - Jack && Jill>";
            this.myButtonInsertData.UseVisualStyleBackColor = true;
            this.myButtonInsertData.Click += new System.EventHandler(this.myButtonInsertData_Click);
            // 
            // myButtonRetrieveData
            // 
            this.myButtonRetrieveData.Enabled = false;
            this.myButtonRetrieveData.Location = new System.Drawing.Point(13, 154);
            this.myButtonRetrieveData.Name = "myButtonRetrieveData";
            this.myButtonRetrieveData.Size = new System.Drawing.Size(196, 42);
            this.myButtonRetrieveData.TabIndex = 4;
            this.myButtonRetrieveData.Text = "Load from Database";
            this.myButtonRetrieveData.UseVisualStyleBackColor = true;
            this.myButtonRetrieveData.Click += new System.EventHandler(this.myButtonRetrieveData_Click);
            // 
            // myButtonCompare
            // 
            this.myButtonCompare.Enabled = false;
            this.myButtonCompare.Location = new System.Drawing.Point(13, 202);
            this.myButtonCompare.Name = "myButtonCompare";
            this.myButtonCompare.Size = new System.Drawing.Size(196, 42);
            this.myButtonCompare.TabIndex = 5;
            this.myButtonCompare.Text = "Compare Objects";
            this.myButtonCompare.UseVisualStyleBackColor = true;
            this.myButtonCompare.Click += new System.EventHandler(this.myButtonCompare_Click);
            // 
            // myButtonDelete
            // 
            this.myButtonDelete.Enabled = false;
            this.myButtonDelete.Location = new System.Drawing.Point(12, 250);
            this.myButtonDelete.Name = "myButtonDelete";
            this.myButtonDelete.Size = new System.Drawing.Size(196, 42);
            this.myButtonDelete.TabIndex = 6;
            this.myButtonDelete.Text = "Delete Object\r\n<Employee - Jack>";
            this.myButtonDelete.UseVisualStyleBackColor = true;
            this.myButtonDelete.Click += new System.EventHandler(this.myButtonDelete_Click);
            // 
            // myButtonDisplay
            // 
            this.myButtonDisplay.Enabled = false;
            this.myButtonDisplay.Location = new System.Drawing.Point(12, 298);
            this.myButtonDisplay.Name = "myButtonDisplay";
            this.myButtonDisplay.Size = new System.Drawing.Size(196, 42);
            this.myButtonDisplay.TabIndex = 7;
            this.myButtonDisplay.Text = "Display Objects from Database";
            this.myButtonDisplay.UseVisualStyleBackColor = true;
            this.myButtonDisplay.Click += new System.EventHandler(this.myButtonDisplay_Click);
            // 
            // myLabelStatus
            // 
            this.myLabelStatus.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.myLabelStatus.Location = new System.Drawing.Point(0, 349);
            this.myLabelStatus.Name = "myLabelStatus";
            this.myLabelStatus.Size = new System.Drawing.Size(224, 23);
            this.myLabelStatus.TabIndex = 8;
            // 
            // FormDemo
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(224, 372);
            this.Controls.Add(this.myLabelStatus);
            this.Controls.Add(this.myButtonDisplay);
            this.Controls.Add(this.myButtonDelete);
            this.Controls.Add(this.myButtonCompare);
            this.Controls.Add(this.myButtonRetrieveData);
            this.Controls.Add(this.myButtonInsertData);
            this.Controls.Add(this.myButtonClearDB);
            this.Controls.Add(this.myButtonConfigure);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.Name = "FormDemo";
            this.Text = "NHibernate Basics";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button myButtonConfigure;
        private System.Windows.Forms.Button myButtonClearDB;
        private System.Windows.Forms.Button myButtonInsertData;
        private System.Windows.Forms.Button myButtonRetrieveData;
        private System.Windows.Forms.Button myButtonCompare;
        private System.Windows.Forms.Button myButtonDelete;
        private System.Windows.Forms.Button myButtonDisplay;
        private System.Windows.Forms.Label myLabelStatus;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Philips
India India
Have been working with computers since the early 00's. Since then I've been building, fixing, configuring, installing, coding and designing with them. At present I mainly code windows applications in C#, WCF, WPF and SQL. I'm very interested in Design Patterns and try and use these generic principles in all new projects to create truly n-tier architectures. Also I like to code for making the User Interface very attractive...

Comments and Discussions