问题描述
所以,一切与基本鉴别映射运作良好。我可以与实体A和B,没有任何问题直接交互
So everything is working well with the basic discriminator mapping. I can interact directly with entities A and B without any problems.
public class BaseType {}
public class EntityA : BaseType {}
public class EntityB : BaseType {}
这没有戏剧映射在BASETYPE映射为
This maps without drama in the BaseType mapping as
DiscriminateSubClassesOnColumn<string>("Type")
.SubClass<BaseType>("A", m => { })
.SubClass<BaseType>("B", m => { });
出现问题时:中,我们要映射集合到一个聚合每个子类
The problem occurs when: in an aggregate we want to map collections to each subclass
使用映射像下面
public class AggregateMap: BaseMap<Aggregate>
{
public AggregateMap()
{
HasMany<EntityA>(x => x.ACollection).AsSet().Cascade.All();
HasMany<EntityB>(x => x.BCollection).AsSet().Cascade.All();
}
}
这些明显的arent完全映射,但最低金额descibe我所尝试。加入ACollection和BCollection项目通过级联坚持正确总结时保存。然而,当总检索有该类型的歧视混淆。
These obviously arent full mappings but are the minimum amount to descibe what I am attempting. Items added to ACollection and BCollection are persisted correctly through the cascading when Aggregate is saved. However, when aggregate is retrieved there is confusion on the type discrimination.
我经历了这么多不同的解决方案我已经不知道什么是没有工作运行。我觉得我不应该提供藏品,但事情就不会为我工作where子句。
I have run through so many different possible solutions I no longer know what didn't work. I feel that I shouldn't have to provide a where clause on the collections but things just aren't working for me.
任何线索,将不胜感激。
Any clues would be appreciated.
推荐答案
您的映射看起来很奇怪,尤其是我觉得应该看的更多这样的
You mapping looks odd, in particular I think it should look more like this
DiscriminateSubClassesOnColumn<string>("Type")
.SubClass<EntityA>("A", m => { })
.SubClass<EntityB>("B", m => { });
说了这么多,似乎方法贬值,您应该定义以下(从自动映射子类:
public class ParentMap : ClassMap<Parent>
{
public ParentMap()
{
Id(x => x.Id);
Map(x => x.Name);
DiscriminateSubClassesOnColumn("type");
}
}
public class ChildMap : SubclassMap<Child>
{
public ChildMap()
{
Map(x => x.AnotherProperty);
}
}
不知道这会虽然修复它,我还没有遇到您的方案。
Not sure this will fix it though, I am yet to encounter your scenario.
修改:这个问题也是引发的,听起来更像是对我的一个错误
Edit: The issue is also raised here, sounding more like a bug to me
这篇关于不同子类型的功能NHibernate实体的hasMany收藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!