假设我有一个Parent和Child表,以及一个ParentChild表来维护它们之间的关系。
家长班:
public class Parent
{
public virtual int ParentId { get; set; }
public virtual bool Deleted { get; set; }
public Parent()
{
_children = new HashedSet<Child>();
}
protected ISet<Child> _children;
public virtual ISet<Child> children
{
get { return _children; }
protected set { _children = value; }
}
}
儿童班:
public class Child
{
public virtual int ChildId { get; set; }
public virtual bool Deleted { get; set; }
public Child()
{
_parents = new HashedSet<Parent>();
}
protected ISet<Parent> _parents;
public virtual ISet<Parent> parents
{
get { return _parents; }
protected set { _parents = value; }
}
}
和ParentChild类:
public class ParentChild
{
public virtual int ParentChildId { get; set; }
public virtual Parent Parent { get; set; }
public virtual Child Child { get; set; }
public virtual int DisplayOrderIndex { get; set; }
public virtual bool Deleted { get; set; }
}
我如何映射这些以便我可以对父对象进行更新,该对象还将使用其他数据(不仅仅是父/子ID)和子表更新联结表。
现在,我正在做:
父地图
public ParentMap()
{
Table("Parent");
Id(x => x.ParentId);
Map(x => x.Deleted);
HasMany(x => x.ParentChild)
.Table("Parent_Child")
.KeyColumn("ParentID")
.Access.CamelCaseField(Prefix.Underscore)
.Cascade.AllDeleteOrphan()
.LazyLoad();
}
儿童地图
public ChildMap()
{
Table("Child");
Id(x => x.ChildId);
Map(x => x.Deleted);
HasMany(x => x.ParentChild)
.Table("Parent_Child")
.KeyColumn("ChildID")
.Access.CamelCaseField(Prefix.Underscore)
.Cascade.AllDeleteOrphan()
.LazyLoad();
}
ParentChild Map
public ParentChildMap()
{
Table("Parent_Child");
Id(x => x.ParentChildId, "Parent_ChildID");
References(x => x.Parent, "ParentID");
References(x => x.Child, "ChildID");
Map(x => x.DisplayOrderIndex);
Map(x => x.Deleted);
}
但是,当我从Parent存储库中提取时,Parent对象的ParentChild集合中的Child是Castle.Proxy而不是Child类型。
如何进行此映射以获得所需的结果?