日期:2014-05-18  浏览次数:20906 次

Could not compile the mapping document: NHDemo.DomainModel.Demo.hbm.xml
开发工具vs2005打过sp1补丁.nhibernate 2.1.0。
项目架构:WebUI,NHDemo.BLL,NHDemo.DAL,NHDemo.DomainModel。
NHDemo.DomainModel:Demo.cs,Demo.hbm.xml
Demo.cs
C# code

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
    }
}


Demo.hbm.xml
XML code

<?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>



NHDemo.DAL:

SessionFactory.cs

C# code

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();
        }

    }
}


 EntityControl.cs:
C# code

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