简体   繁体   English

流利NHibernate映射

[英]Fluent NHibernate Mapping

I have the class filter.cs with this attributes:我有具有以下属性的 class filter.cs:

    public virtual int Id { get; set; }
    public virtual Attribute Attribute { get; set; }
    public virtual Int16 Type { get; set; }
    public virtual string FilterValue { get; set; }
    public virtual ReportConfiguration ReportConfiguration { get; set; }

Attribute and ReportConfiguration are a Foreign Key. Attribute 和 ReportConfiguration 是外键。

I made this mapping:我做了这个映射:

        Id(a => a.Id).UnsavedValue(0).GeneratedBy.Identity();
        Map(a => a.Type);
        Map(a => a.FilterValue);
        References(x => x.ReportConfiguration).Column("IdReportConfiguration").Not.LazyLoad();
        References(x => x.Attribute).Column("IdAttribute").Not.LazyLoad();

In addition, I have a Repository class for example with the method:另外,我有一个存储库 class 例如,方法如下:

public int Create(Filter F)
    {
        int FilterId = 0;
        Transactional(session =>
        {
            FilterId = (int)session.Save(F);
        });
        return FilterId;
    }

And when I did the Unit Test of Create(Filter F) it produced an exception:当我进行Create(Filter F)的单元测试时,它产生了一个异常:

No persister for: ....Filter.cs没有持久性: ....Filter.cs

I think the mapping is not correct.我认为映射不正确。

Any idea?任何想法?

Thanks and best regards.谢谢和最好的问候。

Try here:在这里试试:

Fluent Nhibernate No persister for: Fluent Nhibernate 无持久性:

From the above post:从上面的帖子:

Solution: This error occurs since the class is not public.解决方案:出现此错误是因为 class 未公开。 Just change the class to public and this won't occur again.只需将 class 更改为 public 就不会再发生这种情况。 However, if you do not want to expose the assembly outside the Assembly you can still mark the constructor as 'internal'.但是,如果您不想在程序集之外公开程序集,您仍然可以将构造函数标记为“内部”。

Is this your situation?这是你的情况吗?


This is a similar question:这是一个类似的问题:

Fluent Nhibernate No Persistor for Class Name Fluent Nhibernate No Persistor for Class 名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM