日期:2014-05-18 浏览次数:20906 次
using System; using System.Collections.Generic; using System.Text; namespace NHDemo.DomainModel { public class Demo { public Demo() { } #region private string _demoid; private string _title; public virtual string DemoID { set { _demoid = value; } get { return _demoid; } } public virtual string Title { set { _title = value; } get { return _title; } } #endregion } }
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false"> <class name="NHDemo.DomainModel.Demo, NHDemo.DomainModel" table="WF_DEMO" lazy="false"> <id name="DemoID" column="DEMOID" type="String" length="50"> <generator class="assigned" /> </id> <property name="Title" column="TITLE" type="String" length="500"/> </class> </hibernate-mapping>
using System; using System.Collections.Generic; using System.Text; using NHibernate; using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; namespace NHDemo.DAL { public class SessionFactory { public SessionFactory() { } private static ISessionFactory sessions; private static Configuration cfg; static readonly object padlock = new object(); public static ISession OpenSession(string AssemblyName) { if (sessions == null) { lock (padlock) { if (sessions == null) { BuildSessionFactory(AssemblyName); } } } return sessions.OpenSession(); } private static void BuildSessionFactory(string AssemblyName) { cfg = new Configuration(); cfg.AddAssembly(AssemblyName); //cfg.Configure(ser); sessions = cfg.BuildSessionFactory(); } } }
using System; using System.Collections.Generic; using System.Collections; using System.Text; using NHibernate; namespace NHDemo.DAL { public class EntityControl { public EntityControl() { } private static EntityControl entity; private string _AssemblyName; static readonly object padlock = new object(); public static EntityControl CreateEntityControl(string AssemblyName) { if (entity == null) { lock (padlock) { if (entity == null) { entity = new EntityControl(); entity._AssemblyName = AssemblyName; } } } return entity; } public