views:

25

answers:

2

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?

A: 

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.... :/

Jonathan Pritchard
A: 

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.

lcranf