流利的Nhibernate,Subclass,ManyToMany。表中的关联引用了未映射的类

时间:2010-10-18 15:39:32

标签: c# nhibernate fluent-nhibernate

我正在使用Fluent(1.1.0)NHibernate(2.1.2)并且我有一个(子)子类,其中包含对另一个类的多对多引用:

(子)子类 - <交叉表> - 其他类

FloorplanObject(基类)

几何(子类)

Stand(SubSubclass) - < ExhibitorStand> - 参展商

基类:

public class FloorplanObject
{
    public int Id { get; set; }
    public string Name { get; set; }
}

基类映射:

class FloorplanObjectMap : ClassMap<FloorplanObject>
{
    public FloorplanObjectMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);              
    }
}

子类:

public class Geometry : FloorplanObject
{
    public virtual List<float> Positions { get; set; }

    public Geometry()
    {
        Positions = new List<float>();
    }
}

子类映射:

public class GeometryMap : SubclassMap<Geometry>
{
    public GeometryMap()
    {
        Map(x => x.Positions);
    }
}

(子)子类:

public class Stand : Geometry
{
    public virtual string StandNumber { get; set; }
    public virtual List<Exhibitor> HasExhibitors { get; set; }

    public Stand()
    {
        HasExhibitors = new List<Exhibitor>();
    }
}

(Sub)子类映射:

public class StandMap : SubclassMap<Stand>
{
    public StandMap()
    {
        Map(x => x.StandNumber);
        HasManyToMany(x => x.HasExhibitors)
            .Cascade.All()
            .Inverse()
            .Table("ExhibitorStand");
    }
}

其他课程:

public class Exhibitor
{
    public virtual int Id { get; private set; }
    public virtual string Name { get; set; }

    public virtual List<Stand> OnStands { get; set; }

    public Exhibitor()
    {
        OnStands = new List<Stand>();
    }
}

其他类映射:

public class ExhibitorMap : ClassMap<Exhibitor>
{
    public ExhibitorMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);
        HasManyToMany(x => x.OnStands)
            .Cascade.All()
            .Table("ExhibitorStand");
    }
}

在使用上述映射初始化ISession时,我收到以下错误:

  

NHibernate.MappingException:表ExhibitorStand中的关联引用了一个未映射的类:Stand

有没有人知道我在这里做错了什么?

2 个答案:

答案 0 :(得分:10)

亲爱的,亲爱的。什么假人:

class FloorplanObjectMap : ClassMap<FloorplanObject>
{
    public FloorplanObjectMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);              
    }
}

应该是:

public class FloorplanObjectMap : ClassMap<FloorplanObject>
{
    public FloorplanObjectMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);              
    }
}

如果你浪费时间阅读这篇文章,请道歉。第一个......:/

答案 1 :(得分:1)

您的映射看起来是正确的,看起来您的会话工厂初始化逻辑由于某种原因没有拿起您的StandMap类。只需验证您的Fluently.Configure()代码是否可以访问所有类映射。