持久化类未找到异常

时间:2018-06-13 05:29:54

标签: c# nhibernate

我遇到配置nhibernate的问题。当我想测试我实现的服务器时,H面临一个错误:{"持久化类Tosan.Service.DataAccess.Dao.StudentDao,找不到Tosan.Service.DataAccess"}并且不能编译映射文档:Tosan.Sevrice.DataAccess.Mapping.StudentDao.hbm.xml 和其他例外是​​{"无法加载文件或汇编' Tosan.Service.DataAccess'或其中一个依赖项。系统找不到指定的文件。":" Tosan.Service.DataAccess"}

我的代码在这里:

namespace Tosan.Sevrice.Core.Utility
{
   public class NHibernateHelper
   {

       private NHibernateHelper()
            {
              }


    private static ISessionFactory _sessionFactory;

    private  static readonly object lockObject = new object();

    private static ISessionFactory SessionFactory
    {
        get
        {
            if (_sessionFactory == null)

              lock (lockObject)

              if (_sessionFactory == null)
               {
                  var configuration = new Configuration();
                //   configuration.Configure();
                   configuration.DataBaseIntegration(x =>
                   {
                     x.ConnectionString =
                         "Data Source=ORA811_39.113;" +
                         "User id=TESTR296;" +
                         "Password=Admin1;"
                         ;
                     x.Driver<NHibernate.Driver.OracleDataClientDriver>();
                     x.Dialect<NHibernate.Dialect.Oracle10gDialect>();
                   });

         configuration.AddAssembly("Tosan.Sevrice.DataAccess");

        //configuration.AddAssembly(typeof(StudentDao).Assembly);


            _sessionFactory = configuration.BuildSessionFactory();
              }
            return _sessionFactory;
        }
    }

    public static ISession OpenSession()
    {
        return SessionFactory.OpenSession();
    }
}
}

和我的dao文件映射:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="Tosan.Service.DataAccess" 
namespace="Tosan.Service.DataAccess.Dao" xmlns="urn:nhibernate-mapping-2.2">
  <class name ="StudentDao" table="STUDENTT" lazy="true" >
    <id name ="Id" column="ID">
      <generator class = "increment"/>
    </id>
    <property name = "FirstName" column="FIRSTNAME"/>
    <property name = "LastName" column="LASTNAME" />
    <property name = "degree" column="DEGREE"/>
    <property name = "Feild" column="FEILD"/>

  </class>
</hibernate-mapping>

和我的学生:

namespace Tosan.Sevrice.DataAccess.Dao
{
    public class StudentDao
    {
        public virtual int Id { get; set; }
        public virtual string FirtName { get; set; }
        public virtual string LastName { get; set; }
        public virtual string degree { get; set; }
        public virtual string Feild { get; set; }

    }
}

我该怎么办?请帮我。我搜索了互联网,但我找不到任何有用的东西。 在堆栈跟踪中:

   at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
   at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName)
   at NHibernate.Cfg.Configuration.ProcessMappingsQueue()
   at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
   at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
   at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
   at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
   at Tosan.Sevrice.Core.Utility.NHibernateHelper.get_SessionFactory() in C:\Users\\documents\visual studio 2015\Projects\contract\Tosan.Sevrice.Core\Utility\NHibernateHelper.cs:line 46
   at Tosan.Sevrice.Core.Utility.NHibernateHelper.OpenSession() in C:\Users\\documents\visual studio 2015\Projects\contract\Tosan.Sevrice.Core\Utility\NHibernateHelper.cs:line 59
   at Tosan.Service.Core.rep.SService.Add(StudentDto std) in C:\Users\\documents\visual studio 2015\Projects\contract\Tosan.Sevrice.Core\Repository\SService.cs:line 18
   at Tosan.Service.Implementation.StudentService.Add(StudentDto std) in C:\Users\\documents\visual studio 2015\Projects\contract\Tosan.Service\Implementation\StudentService.cs:line 18
   at SyncInvokeAdd(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

0 个答案:

没有答案