它能够流利HasManyToMany双方与noop地图
-
25-09-2019 - |
题
我想地图POCO作为一个多对多关系。我不想要一个属性行为,其中包含BehavioralEvents.我很确定的许多对多映必须在这两个地方,但是我不想的相应的财产上我的行为类。
我听说过你可以使用一个没有运入运营商,但我不知道该如何做到这一点,在它能够流利.
请提醒:
public class BehavioralEvent : AggregateRoot
{
protected internal IList<Behavior> Behaviors { get; private set; }
public BehavioralEvent()
{
Behaviors = new List<Behavior>();
}
}
行为类中(没有引用回BehavioralEvent)
public class Behavior : AggregateRoot
{
protected internal virtual string Name { get; private set; }
protected internal virtual string Definition { get; private set; }
public Behavior(string name, Guid id)
{
this.Id = id;
this.Name = name;
}
protected Behavior(){}
}
BehavioralEventClassMap:
public class BehavioralEventClassMap : ClassMap<BehavioralEvent>
{
public BehavioralEventClassMap()
{
Id(x => x.Id, "BehavioralEventId").GeneratedBy.Assigned();
HasManyToMany(x => x.Behaviors)
.Cascade.All()
.Table("BehaviorData")
.ParentKeyColumn("BehavioralEventId")
.ChildKeyColumn("BehaviorId");
}
}
BehaviorClassMap:
public class BehaviorClassMap : ClassMap<Behavior>
{
public BehaviorClassMap()
{
Table("Behaviors");
Id(x => x.Id, "BehaviorId").GeneratedBy.Assigned();
Map(x => x.Name).Not.Nullable();
Map(x => x.Definition);
}
}
解决方案
你不需要地图,它从两个方面。
我有各种各样的映射是这样的:
HasManyToMany(x => x.SomeCollection).Table("MappingTable").ParentKeyColumn("ParentKey").ChildKeyColumn("ChildKey").Cascade.AllDeleteOrphan();
就像一个魅力!地图这样的收集,或设置(见 http://www.codinginstinct.com/2010/03/nhibernate-tip-use-set-for-many-to-many.html).
其他提示
如果你不需要自行为再没添加在映射。如果你需要的并不想把操作然后使用瀑布。没有()
不隶属于 StackOverflow