映射异常NHibertnate

时间:2014-01-19 22:48:20

标签: c# nhibernate nhibernate-mapping

我正在学习如何使用SQLite数据库在C#中使用NHibernate进行映射的示例和讲座。到目前为止,我有:

hibernate.cfg.xml中:

<?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.driver_class">NHibernate.Driver.SQLite20Driver</property>
    <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
    <property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    <property name="query.substitutions">true=1;false=0</property>
    <property name="show_sql">false</property>
</session-factory>
</hibernate-configuration>
</configuration>

FavoritePage.cs

namespace Example
{
    public class FavoritePage
    {

        private int _id;
        private string _name;
        private string _website;


        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }


        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Website
        {
            get { return _website; }
            set { _website = value; }
        }


        public FavoritePage()
        { }


        public FavoritePage(String inName, String inWebsite)
        {
            Name = inName;
            Website = inWebsite;
        }
    }
}

FavoritePage.hbm.xml (签名为嵌入式资源)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
  <class name="Example.FavoritePage, Example" lazy="false">

    <id name="_id" access="field">
      <generator class="native" />
    </id>

    <property name="_name" access="field" column="name"/>
    <property name="_website" access="field" column="website"/>

  </class>
</hibernate-mapping>

FavoritePageRepository.cs

namespace Example
{
public class FavoritePagesRepository
{


    static ISession OpenSession()
    {
        Configuration c = new Configuration();
        c.AddAssembly(Assembly.GetCallingAssembly());
        ISessionFactory f = c.BuildSessionFactory();
        return f.OpenSession();
    }

    public static void addFavoritePage(FavoritePage favoritePage)
    {
        using (ISession session = OpenSession())
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(favoritePage);
                transaction.Commit();
            }
        }
    }
}

}

执行行c.AddAssembly(Assembly.GetCallingAssembly());时抛出异常,说:无法编译映射文档:Example.FavoritePage.hbm.xml。有人可以告诉我在哪里弄错了吗?

0 个答案:

没有答案
相关问题