0
我有以下情况:组合模型插入问题
我有2个班(儿童)和复合类(父):
public Parent
{
public ChildOne C1 {get;set;}
public ChildTwo C2 {get;set;}
}
public ChildOne
{
public int Id{get;set;}
...some primitive fields
}
public ChildTwo
{
public int Id{get;set;}
...other primitive fields
}
这些类的映射是以下:
public class Parent: ClassMap<Parent>
{
public ParentMap()
{
Table("Parents");
Id(x => x.Id).Column("ParentId");
References(x => x.C1).Column("ChildOneId");
References(x => x.C2).Column("ChildTwoId");
}
}
和
public class ChildOne: ClassMap<ChildOne>
{
public ChildOneMap()
{
Table("ChildOnes");
Id(x => x.Id).Column("ChildOneId");
...other Mappings for primitive types
}
}
(对于ChildTwo也是如此)。
的DB如下:
Parents: ParentId, ChildOneId, ChildTwoId
ChildOne: ChildOneId, ...other columns
ChildOne: ChildTwoId, ...other columns
和关系ChildOneId(父母)< ==> ChildOneId(ChildOnes)。
当我想要在相应的孩子的Db中插入一个新的Parent时,我得到一个ChildOneId/ChildTwoId不能为null的错误。
为了使插入工作,我需要在映射类中指定什么? (检索操作正常工作)
感谢, Tamash
您可以发布您用于创建父对象的代码以及它如何填充ChildOne&ChildTwo属性? – 2012-03-15 14:19:31