.net nHibernate域模型和单独项目中的映射文件

.net nHibernate域模型和单独项目中的映射文件,.net,nhibernate,.net,Nhibernate,有没有办法将域对象和映射文件分离到两个单独的项目中?我想创建一个名为MyCompany.MyProduct.Core的项目,其中包含我的域模型,另一个名为MyCompany.MyProduct.Data.Oracle的项目,其中包含我的Oracle数据映射。但是,当我尝试进行单元测试时,会收到以下错误消息: 找不到命名查询“GetClient” 这是我的映射文件: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"

有没有办法将域对象和映射文件分离到两个单独的项目中?我想创建一个名为MyCompany.MyProduct.Core的项目,其中包含我的域模型,另一个名为MyCompany.MyProduct.Data.Oracle的项目,其中包含我的Oracle数据映射。但是,当我尝试进行单元测试时,会收到以下错误消息:

找不到命名查询“GetClient”

这是我的映射文件:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="MyCompany.MyProduct.Core"
                   namespace="MyCompany.MyProduct.Core"                   
                   >
  <class name="MyCompany.MyProduct.Core.Client" table="MY_CLIENT" lazy="false">
    <id name="ClientId" column="ClientId"></id>
    <property name="ClientName" column="ClientName" />
    <loader query-ref="GetClients"/>
  </class>
  <sql-query name="GetClients" callable="true">
    <return class="Client" />
    call procedure MyPackage.GetClients(:int_SummitGroupId)
  </sql-query>
</hibernate-mapping>

调用过程MyPackage.GetClients(:int\u SummitGroupId)
下面是我的单元测试:

        try
        {
            var cfg = new Configuration();
            cfg.Configure();
            cfg.AddAssembly( typeof( Client ).Assembly );

            ISessionFactory sessionFactory = cfg.BuildSessionFactory();
            IStatelessSession session = sessionFactory.OpenStatelessSession();

            IQuery query = session.GetNamedQuery( "GetClients" );
            query.SetParameter( "int_SummitGroupId", 3173 );
            IList<Client> clients = query.List<Client>();

            Assert.AreNotEqual( 0, clients.Count );
        }
        catch( Exception ex )
        {
            throw ex;
        }
试试看
{
var cfg=新配置();
Configure();
cfg.AddAssembly(typeof(Client.Assembly));
ISessionFactory sessionFactory=cfg.BuildSessionFactory();
IStatelessSession session=sessionFactory.OpenStatelessSession();
IQuery=session.GetNamedQuery(“GetClients”);
SetParameter(“int_SummitGroupId”,3173);
IList clients=query.List();
Assert.AreNotEqual(0,clients.Count);
}
捕获(例外情况除外)
{
掷骰子;
}

我想我可能引用的程序集不正确,因为如果我将域模型对象放在mycmapny.MyProduct.Data.Oracle类中,它就会工作。只有当我分成两个项目时,我才会遇到这个问题

是的,这是可能的。如果映射位于程序集“MyCompany.MYProduct.Data.Oracle”上,则必须将该程序集传递给cfg.AddAssembly()。您正在使用程序集“MyCompany.MyProduct.Core”


cfg.AddAssembly(“MyCompany.MYProduct.Data.Oracle”)

谢谢!这正是我需要的答案。