NHibernate MappingException.没有Persister [英] NHibernate MappingException. No Persister

查看:100
本文介绍了NHibernate MappingException.没有Persister的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让NHibernate工作.我有这节课:

I'm trying to get NHibernate to work. I've got this class:

mm.k.Domain.Kampagne

(名称空间/程序集是mm.k.Domain)

(namespace/assembly is mm.k.Domain)

在另一个Visual Studio项目(Assembly mm.k.Infrastructure)中,获得了Mapping文件(位于Mappings目录中),hibernate.cfg.xml和一些存储库.

In another Visual Studio project (Assembly mm.k.Infrastructure) I got my Mapping files (in a Mappings directory), my hibernate.cfg.xml and some repositories.

这里有我的映射文件:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="mm.k.Domain"
                   namespace="mm.k.Domain">

  <class name="Kampagne" table="Kampagner">
    <id name="Id">
      <generator class="identity" />
    </id>
    <property name="Navn" not-null="true" />
    <property name="Logo" />
  </class>

</hibernate-mapping>

在配置会话时,请执行以下操作:

When I'm configuring my session, I do this:

_configuration.AddAssembly(typeof(mm.k.Domain.Kampagne).Assembly);

那是行不通的! 呼叫时:

And thats what doesn't work! When calling:

var test = session.Get<Kampagne>(kampagneId);

我收到以下错误: 没有持久性:mm.k.Domain.Kampagne" 就像它没有注册嵌入式映射fild一样.请注意,我已将映射文件的构建操作设置为嵌入式资源".

I get the following error: "No persister for: mm.k.Domain.Kampagne" Like it doesn't register the embedded mapping fild. Note that I have the build action on the mapping file set to Embedded Resource.

如果我将以上行更改为:

If I change the above line to:

_configuration.AddFile(@"fullpath\mm.k.Infrastructure\Mappings\Kampagne.hbm.xml");

一切正常!

有什么想法吗?预先感谢.

Any ideas? Thanks in advance.

推荐答案

不确定您的nhibernate.cfg.xml文件是什么样,但是我通常有一个类似这样的项目

Not sure what your nhibernate.cfg.xml file looks like, but I generally have an item like this

<mapping assembly="mm.K.Infrastructure"/>

根据您提供的信息. NHibernate使用它从该特定程序集中加载映射文件.

based on your information you've given. NHibernate uses this to load the mapping files from this specific assembly.

这应该为您提供所需的映射.

This should give you the mapping you need.

这篇关于NHibernate MappingException.没有Persister的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆