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

Nhibernate中 User is not mapped
上代码
XML code
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="MyHibernate.Model" assembly="Model">
    <class name="MyHibernate.Model.User" table="Users">
        <id name="Id">
            <generator class="native"></generator>
        </id>
        <property name="UserName"></property>
        <property name="Pwd"></property>
        <property name="CreateDate"></property>
        <property name="Power"></property>
    </class>
</hibernate-mapping>

C# code
 public class UserRepository:BaseRepository<User>
    {
        public IList<User> GetAllUser()
        {
            return _sessionFactory.Session().CreateQuery("from User").List<User>();
        }
    }


XML配置属性也改过了。

------解决方案--------------------
<session-factory>
<mapping assembly="Model"/>

实体类 属性 要设 virtual


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Model"
namespace ="Model"
------解决方案--------------------
探讨

<session-factory>
<mapping assembly="Model"/>

实体类 属性 要设 virtual


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Model"
namespace ="……