Click here to Skip to main content
15,881,715 members
Articles / NHibernate

Object Relational Mapping (ORM) using NHibernate - Part 7 of 8 Completing the Ecommerce Example

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
15 May 2013CPOL7 min read 28K   2.6K   17  
A full series of 8 part articles to show One-To-One, Many-To-One, Many-To-Many associations mapping using NHibernate, Using Collections With NHibernate, Inheritance Relationships Using NHibernate, Lazy Initializations/Fetches Using NHibernate.
using System;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace ECommerceSystem.Repository
{
    public interface IRepository<T>
    {
        void addItem(T item);

        void removeItem(T item);

        void updateItem(T item);

        T getItemById(long item_id);

        int  getItemCount();


    }

    internal class NHibernateHelper
    {
        private NHibernateHelper()
        {
            Configuration cfg = new Configuration();
            cfg.Configure();
            sessionFactory = cfg.BuildSessionFactory();
            new SchemaExport(cfg).Execute(false, true, false); 
        }

        public static NHibernateHelper Create()
        {
            if (nHibHelper == null)
            {

                try
                {
                    nHibHelper = new NHibernateHelper();
                }
                catch (Exception ex)
                {
                    nHibHelper = null;
                }
            }

            return nHibHelper;
        }
        public ISession Session
        {
            get { return sessionFactory.OpenSession(); }
        }
        ISessionFactory sessionFactory;
        static NHibernateHelper nHibHelper;
    }
}

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
India India
Software Developer developing in c#.net.

Comments and Discussions