zoukankan      html  css  js  c++  java
  • 学习NHibernate遇到的问题

    在写NHibernate的时候,遇到了:
    未能加载文件或程序集“NHibernateDemoWebSite”或它的某一个依赖项。系统找不到指定的文件
    以下是错误提示代码:
     1行 31:         //    .AddDirectory(new System.IO.DirectoryInfo(HostingEnvironment.MapPath("~/App_Data/")));
     2行 32
     3行 33:         config = new NHibernate.Cfg.Configuration().AddAssembly("NHibernateDemoWebSite");
     4行 34
     5行 35:         //.SetDefaultAssembly(typeof(TUserInfo).Assembly.FullName)
     6
     7堆栈跟踪: 
     8
     9
    10[FileNotFoundException: 未能加载文件或程序集“NHibernateDemoWebSite”或它的某一个依赖项。系统找不到指定的文件。]
    11   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
    12   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +211
    13   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +141
    14   System.Reflection.Assembly.Load(String assemblyString) +25
    15   NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) +62
    16
    17[MappingException: Could not add assembly NHibernateDemoWebSite]
    18   NHibernate.Cfg.Configuration.LogAndThrow(MappingException me) +38
    19   NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) +116
    20   DataAccessFactory..cctor() in e:\学习\Net\NHibernateDemoWebSite\App_Code\DataAccessFactory.cs:33
    21
    22[TypeInitializationException: “DataAccessFactory”的类型初始值设定项引发异常。]
    23   _Default.Page_Load(Object sender, EventArgs e) in e:\学习\Net\NHibernateDemoWebSite\Default.aspx.cs:21
    24   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
    25   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
    26   System.Web.UI.Control.OnLoad(EventArgs e) +99
    27   System.Web.UI.Control.LoadRecursive() +47
    28   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
    29 
    30

    以下是我写的一部分代码:
    DataAccessFactory.cs
     1using System;
     2using System.Data;
     3using System.Configuration;
     4using System.Web;
     5using System.Web.Security;
     6using System.Web.Hosting;
     7using System.Web.UI;
     8using System.Web.UI.WebControls;
     9using System.Web.UI.WebControls.WebParts;
    10using System.Web.UI.HtmlControls;
    11using NHibernate;
    12using NHibernate.Cfg;
    13using NHibernateDemoWebSite;
    14
    15/// <summary>
    16/// DataAccessFactory 的摘要说明
    17/// </summary>

    18public class DataAccessFactory : HttpApplication
    19{
    20
    21    public static readonly NHibernate.Cfg.Configuration config;
    22    public static readonly NHibernate.ISessionFactory sessionFactory;
    23
    24    static DataAccessFactory()
    25    {
    26        //log4net.Config.XmlConfigurator.Configure();
    27        //config = new NHibernate.Cfg.Configuration();
    28        //Console.Write(typeof(TUserInfo).Assembly.FullName);
    29        //config.SetDefaultAssembly(typeof(TUserInfo).Assembly.FullName)
    30        //    .SetDefaultNamespace(typeof(TUserInfo).Namespace)
    31        //    .AddDirectory(new System.IO.DirectoryInfo(HostingEnvironment.MapPath("~/App_Data/")));
    32
    33        config = new NHibernate.Cfg.Configuration().AddAssembly("NHibernateDemoWebSite");
    34
    35        //.SetDefaultAssembly(typeof(TUserInfo).Assembly.FullName)
    36        //.SetDefaultNamespace(typeof(TUserInfo).Namespace)
    37        //.AddDirectory(new System.IO.DirectoryInfo(HostingEnvironment.MapPath("~/App_Code")));
    38
    39        //config = new NHibernate.Cfg.Configuration()
    40        //        .SetDefaultAssembly(typeof(Item).Assembly.FullName)
    41        //        .SetDefaultNamespace(typeof(Item).Namespace)
    42        //        .AddDirectory(new DirectoryInfo(HostingEnvironment.MapPath("~/App_Data/")));
    43
    44        sessionFactory = config.BuildSessionFactory();
    45    }

    46
    47    public static ISession GetCurrenSession()
    48    {
    49        return sessionFactory.GetCurrentSession();
    50    }

    51}

    52
    注:注释部分是NHibernate源码里的Demo,我按照他的做法,但是还是出现了这样的问题

    以下是实体类:
      1//TUserInfo.cs
      2
      3using System;
      4using System.Collections;
      5using System.Web.UI.WebControls;
      6
      7namespace NHibernateDemoWebSite
      8{
      9    TUserInfo
    615}

    616

    映射文件:
      1<!--TUserInfo.hbm.xml-->
      2<?xml version="1.0" encoding="utf-8" ?>
      3<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
      4    <class name="NHibernateDemoWebSite.TUserInfo, NHibernateDemoWebSite" table="T_UserInfo">
      5        <id name="Id" type="Int32" unsaved-value="null">
      6            <column name="FuserID" length="4" sql-type="int" not-null="true" index="PK_T_USERINFO"/>
      7            <column name="FUserLoginName" length="50" sql-type="varchar" not-null="true" index="PK_T_USERINFO"/>
      8            <generator class="native" />
      9        </id>
     10        <property name="FUserPassWord" type="String">
     11            <column name="FUserPassWord" length="50" sql-type="varchar" not-null="false"/>
     12        </property>
     13        <property name="FCPPassWord" type="String">
     14            <column name="FCPPassWord" length="50" sql-type="varchar" not-null="true"/>
     15        </property>
     16        <property name="FUserTrueName" type="String">
     17            <column name="FUserTrueName" length="50" sql-type="varchar" not-null="false"/>
     18        </property>
     19        <property name="FIDCard" type="String">
     20            <column name="FIDCard" length="50" sql-type="varchar" not-null="false"/>
     21        </property>
     22        <property name="FSex" type="Byte">
     23            <column name="FSex" length="1" sql-type="tinyint" not-null="false"/>
     24        </property>
     25        <property name="FBrithday" type="DateTime">
     26            <column name="FBrithday" length="8" sql-type="datetime" not-null="false"/>
     27        </property>
     28        <property name="FEmail" type="String">
     29            <column name="FEmail" length="50" sql-type="varchar" not-null="false"/>
     30        </property>
     31        <property name="FMobile" type="String">
     32            <column name="FMobile" length="20" sql-type="varchar" not-null="false"/>
     33        </property>
     34        <property name="FTelephone" type="String">
     35            <column name="FTelephone" length="20" sql-type="varchar" not-null="false"/>
     36        </property>
     37        <property name="FQQ" type="String">
     38            <column name="FQQ" length="20" sql-type="varchar" not-null="false"/>
     39        </property>
     40        <property name="Fcode" type="String">
     41            <column name="Fcode" length="10" sql-type="nvarchar" not-null="false"/>
     42        </property>
     43        <property name="FCardProvince" type="String">
     44            <column name="FCardProvince" length="50" sql-type="varchar" not-null="false"/>
     45        </property>
     46        <property name="FCardCity" type="String">
     47            <column name="FCardCity" length="50" sql-type="varchar" not-null="false"/>
     48        </property>
     49        <property name="FAddress" type="String">
     50            <column name="FAddress" length="100" sql-type="varchar" not-null="false"/>
     51        </property>
     52        <property name="FIcon" type="String">
     53            <column name="FIcon" length="100" sql-type="varchar" not-null="false"/>
     54        </property>
     55        <property name="FQuestion" type="String">
     56            <column name="FQuestion" length="100" sql-type="varchar" not-null="false"/>
     57        </property>
     58        <property name="FAnswer" type="String">
     59            <column name="FAnswer" length="100" sql-type="varchar" not-null="false"/>
     60        </property>
     61        <property name="FGetPwdNum" type="String">
     62            <column name="FGetPwdNum" length="100" sql-type="varchar" not-null="false"/>
     63        </property>
     64        <property name="FisRight" type="Byte">
     65            <column name="FisRight" length="1" sql-type="tinyint" not-null="false"/>
     66        </property>
     67        <property name="FLastGetPassWordTime" type="DateTime">
     68            <column name="FLastGetPassWordTime" length="8" sql-type="datetime" not-null="false"/>
     69        </property>
     70        <property name="FGetPassWordNum" type="Int32">
     71            <column name="FGetPassWordNum" length="4" sql-type="int" not-null="false"/>
     72        </property>
     73        <property name="Fip" type="String">
     74            <column name="Fip" length="100" sql-type="nvarchar" not-null="false"/>
     75        </property>
     76        <property name="FloginTimes" type="Int32">
     77            <column name="FloginTimes" length="4" sql-type="int" not-null="false"/>
     78        </property>
     79        <property name="FAmount" type="Decimal">
     80            <column name="FAmount" length="8" sql-type="money" not-null="false"/>
     81        </property>
     82        <property name="FAmountFreeze" type="Decimal">
     83            <column name="FAmountFreeze" length="8" sql-type="money" not-null="false"/>
     84        </property>
     85        <property name="FAllAmount" type="Decimal">
     86            <column name="FAllAmount" length="8" sql-type="money" not-null="false"/>
     87        </property>
     88        <property name="FcardBankType" type="String">
     89            <column name="FcardBankType" length="10" sql-type="varchar" not-null="false"/>
     90        </property>
     91        <property name="FCardName" type="String">
     92            <column name="FCardName" length="50" sql-type="varchar" not-null="false"/>
     93        </property>
     94        <property name="FCardAccount" type="String">
     95            <column name="FCardAccount" length="100" sql-type="varchar" not-null="false"/>
     96        </property>
     97        <property name="Fcredit" type="Int32">
     98            <column name="Fcredit" length="4" sql-type="int" not-null="false"/>
     99        </property>
    100        <property name="FRank" type="String">
    101            <column name="FRank" length="20" sql-type="varchar" not-null="false"/>
    102        </property>
    103        <property name="FUserType" type="Byte">
    104            <column name="FUserType" length="1" sql-type="tinyint" not-null="false"/>
    105        </property>
    106        <property name="FUserTypeState" type="Byte">
    107            <column name="FUserTypeState" length="1" sql-type="tinyint" not-null="false"/>
    108        </property>
    109        <property name="FUserTypeImageUrl" type="String">
    110            <column name="FUserTypeImageUrl" length="100" sql-type="varchar" not-null="false"/>
    111        </property>
    112        <property name="FStatus" type="Byte">
    113            <column name="FStatus" length="1" sql-type="tinyint" not-null="false"/>
    114        </property>
    115        <property name="FisActive" type="String">
    116            <column name="FisActive" length="100" sql-type="varchar" not-null="false"/>
    117        </property>
    118        <property name="Fregtime" type="DateTime">
    119            <column name="Fregtime" length="8" sql-type="datetime" not-null="false"/>
    120        </property>
    121        <property name="Flastlogintime" type="DateTime">
    122            <column name="Flastlogintime" length="8" sql-type="datetime" not-null="false"/>
    123        </property>
    124    </class>
    125</hibernate-mapping>
    126

  • 相关阅读:
    BGP Reflector(反射器)配置实例
    BGP Confederation配置实例
    OSPF Stub配置实例
    OSPF虚链路配置实例
    OSPF多区域配置实例
    数据库用varchar存储时间时会出现时间差解决办法
    判断是否为微信内置浏览器
    PHP中获取文件扩展名
    PHP中$_SERVER的详细参数与说明
    php查询字符串是否存在 strpos
  • 原文地址:https://www.cnblogs.com/shing/p/817892.html
Copyright © 2011-2022 走看看