Fluent Nhibernate,子类,ManyToMany。表中的关联引用未映射的类
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哦亲爱的。什么是假人:
应该是:
如果您浪费时间阅读这篇文章,我深表歉意。第一个也是......:/
Oh dear. what a dummy:
Should be:
Apologies if you wasted your time reading this post. First one too.... :/
您的映射看起来正确,看起来您的会话工厂初始化逻辑由于某种原因没有选择您的 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.