0
我仍然试图绕过LINQ to SQL和外键关系。Linq to SQL外键和集合
我有一张名为“Parent”的表,另一个名为“Children”。我有一个OneToMany关系,父母可以有多个孩子。我DBML看起来像:
<Table Name="" Member="Parents">
<Type Name="Parent">
<Column Member="ParentID" Type="System.String" IsPrimaryKey="true" CanBeNull="false" />
<Column Member="ChildID" Type="System.String" CanBeNull="false" />
<Association Name="Parent_Child" Member="Childs" ThisKey="ParentID" OtherKey="ParentID" Type="Child" />
</Type>
</Table>
<Table Name="" Member="Childs">
<Type Name="Child">
<Column Member="ChildID" Type="System.String" IsPrimaryKey="true" CanBeNull="false" />
<Column Member="ParentID" Type="System.String" CanBeNull="false" />
<Association Name="Parent_Child" Member="Parent" ThisKey="ParentID" OtherKey="ParentID" Type="Parent" IsForeignKey="true" />
</Type>
</Table>
在我的代码,我想这样做的东西,如:
// parent has already been loaded from the datacontext
parent.Childs = <some collection of children>
db.SubmitChanges();
但是,当我这样做,我得到以下错误:
成员定义对象的身份不能改变。 考虑添加一个具有新身份的新对象,并删除现有的对象。
谁能告诉我如何正确完成这个?
是否使用相同的数据上下文或不同的子记录检索? – 2010-12-23 17:01:40
它们是从相同的数据上下文中检索的。 – Addy 2010-12-23 17:08:30