Fluent Nhibernate,子类,ManyToMany。表中的关联引用未映射的类

发布于 2024-09-28 03:33:58 字数 2339 浏览 3 评论 0原文

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

(Sub)Sub Class --< Cross Table>--其他类

FloorplanObject(基类)

Geometry(子类)

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>();
    }
}

子)子类映射:

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

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

I'm using Fluent(1.1.0) NHibernate(2.1.2) and I've got a (sub)subclass with a many-to-many reference to another class:

(Sub)Sub Class --< Cross Table >-- Other Class

or

FloorplanObject (base class)

Geometry (Subclass)

Stand (SubSubclass) --< ExhibitorStand >-- Exhibitor

Base Class:

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

Base Class Mapping:

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

Sub Class:

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

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

Sub Class Mapping:

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

(Sub) Sub Class:

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

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

(Sub) Sub Class Mapping:

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

Other Class:

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>();
    }
}

Other Class Mapping:

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

On initializing an ISession with the above mappings I get the following error:

NHibernate.MappingException: An association from the table ExhibitorStand refers to an unmapped class: Stand

Does anyone have a clue as to what I'm doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小墨 2024-10-05 03:33:58

哦亲爱的。什么是假人:

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);              
    }
}

如果您浪费时间阅读这篇文章,我深表歉意。第一个也是......:/

Oh dear. what a dummy:

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

Should be:

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

Apologies if you wasted your time reading this post. First one too.... :/

花海 2024-10-05 03:33:58

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

Your mappings look correct, it looks like your Session Factory initialization logic is not picking up your StandMap class for some reason. Just verify that your Fluently.Configure() code can access all of your class mappings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文