急啊!!Nhibernate报错:dbo.UserInfo is not mapped [SELECT dbo.UserInfo.U_Name, dbo.UserInfo.U_NickName, dbo.UserInfo.U_LoginPas, dbo.UserTypeInfo.T_Name FROM dbo.UserInfo CROSS JOIN dbo.UserTypeInfo] 
本人代码如下:一般网上都是 大小写不认真导致的这种问题,但是我这不是,查了好久。各位帮忙解决下,多谢!
  <!--用户类型实体类-->
 public  class UserTypeInfo
    {
        public virtual int T_Id { get; set; }
        public virtual string T_Name { get; set; }
        public virtual ISet<UserInfo> UserInfo { get; set;}
    }
  <!--用户类型实体类Mapp文件-->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model.Entities">  <class name="Model.Entities.UserTypeInfo,Model" table="UserTypeInfo">
    
    <!-- 主键,generator为自增长-->    <id name="T_Id" column="T_Id" type="Int32" unsaved-value="0">      <generator class="native"></generator>    </id>    <!--各个字段 -->
    <property name="T_Name" column="T_Name" type="string" length="50" not-null="false"></property>    <!--一个UserTypeInfo对应多个UserInfo-->
    <set name="UserInfo" table="UserInfo" generic="true" inverse="true">      <key column="UserTypeInfo" foreign-key="FK_UserTypeInfoUserInfo"/>      <one-to-many class="Model.Entities.UserInfo,Model"/>    </set>  </class></hibernate-mapping>
  <!--用户信息实体类-->   public  class UserInfo
    {
        //U_Id, U_Name, U_NickName, U_LoginPas, UserTypeInfo
        public virtual int U_Id { get; set; }
        public virtual string U_Name { get; set; }
        public virtual string U_NickName { get; set; }
        public virtual string U_LoginPas { get; set; }
        //public virtual Int32 UserTypeInfo { get; set;}
        public virtual UserTypeInfo UserTypeInfo { get; set; }
    }
  <!--用户信息实体类Mapp文件--><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model.Entities">  <class name="Model.Entities.UserInfo,Model" table="UserInfo">    <id name="U_Id" column="U_Id" type="Int32" unsaved-value="0">      <generator class="native"/>    </id>    <property name="U_Name" column ="U_Name" type="string" not-null="true"></property>
    <property name="U_NickName" column="U_NickName" type="string" not-null="true"></property>
    <property name="U_LoginPas" column="U_LoginPas" type="string" not-null="true"></property>
    <!--<property name="UserTypeInfo" column="UserTypeInfo" type="Int32" not-null="false"></property>-->
    <!--多个UserInfo属于一个UserTypeInfo-->
    <many-to-one name="UserTypeInfo" column="UserTypeInfo" not-null="true" class="Model.Entities.UserTypeInfo,Model"  
                 foreign-key="FK_UserTypeInfoUserInfo"/>
  </class></hibernate-mapping>
<!--业务逻辑层代码(页面调用业务逻辑层的方法就不写出来了)-->
   public static class UserInfoService
    {
       private static readonly IUserInfo ul = DataAccess.CreateUser();
       public static IList<UserInfo> GetAllUserInfo()
       {
           return ul.GetAllUserInfoByHql();
       }    }  
<!--数据访问层代码--> public class UserInfoDAL:IUserInfo
    {
        private EntityControl<UserInfo> entityControl;
        public UserInfoDAL()
        {
            entityControl = new EntityControl<UserInfo>();
        }
        public IList<UserInfo> GetAllUserInfoByHql()
        {
           return entityControl.GetEntitiesList("SELECT dbo.UserInfo.U_Name, dbo.UserInfo.U_NickName, dbo.UserInfo.U_LoginPas, dbo.UserTypeInfo.T_Name FROM dbo.UserInfo CROSS JOIN dbo.UserTypeInfo");
        }
    }       
封装的公共的方法:
 public IList<T> GetEntitiesList(string Hql)
        {
            if (!session.IsConnected)
            {
                session.Reconnect();
            }
            using (ITransaction transaction = session.BeginTransaction())
            {
                IList<T> entities = null;
                try
                {
                    entities = session.CreateQuery(Hql).List<T>();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    session.Disconnect();
                }
                return entities;
            }
        }

解决方案 »

  1.   

    这是.net版,
    去jave hibernate问
      

  2.   

    Nhibernate 就是用于asp.net的吧
      

  3.   

    对象字段和你的select出来的字段个数相同吗
      

  4.   

    .hbm.xml文件是否设置为了:嵌入的资源
      

  5.   


    感谢lchy110   我把文件删除了在增加就报错了!找了一天也没能找到答案!  具体操作是 选中文件--〉属性-- 在文件属性里有个生成操作  设置这个属性的值  
      

  6.   

    去cnblogs上问李永京,他搞这个的。
      

  7.   

    那是你的语句执行时没有得到预期结果,是空值的原因。如果逻辑上确实需要出现空值,那么可以家一组try……catch……解决。否则的话,就查看一下逻辑上哪里有漏洞吧。
      

  8.   

    这个错误除了不认大小写或者字段输入错误,还有没有设置为嵌入式资源这两个因素外,还有其他的因素么?我今天也遇到了这个问题。所有代码都对照了一下,没有发现字段不一致或者大小写错误的地方,也设置为嵌入式资源了。可就是不行,总是报错。现在我的程序已经成功完成4个表的映射了,问题就卡在了这第5个上。郁闷啊。
    比如说,是不是映射名称中不能有下划线?例如“NP_AssessmentPoint”这个表映射的时候。