我正在尝试将 POCO 映射为多对多关系。我不想要包含 BehavioralEvents 的 Behavior 属性。我很确定多对多映射必须在两个地方,但是我不希望我的 Behavior 类上有相应的属性。
我听说您可以使用无操作访问运算符,但我不确定如何在 Fluent Nhibernate 中执行此操作。
请指教:
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(){}
}
行为事件类映射:
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");
}
}
行为类映射:
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);
}
}