저는 LINQ를 SQL 및 외래 키 관계로 변환하려고 계속 노력하고 있습니다.Linq to SQL 외래 키 및 모음
"부모"라는 테이블과 "어린이"라는 테이블이 있습니다. 부모가 여러 자녀를 가질 수있는 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();
을하지만, 나는 다음과 같은 오류 얻을 수행 할 때
회원을 개체의 ID를 정의하는 것은 변경할 수 없습니다. 새 개체를 새 ID로 추가하고 기존 ID를 삭제하는 것이 좋습니다.
아무도 제대로 수행 할 수있는 방법을 말해 줄 수 있습니까?
이 실제로 데이터 컨텍스트의 오류가
동일한 데이터 컨텍스트를 사용하거나 다른 데이터 컨텍스트를 사용하여 하위 레코드를 검색 했습니까? –
동일한 datacontext에서 검색되었습니다. – Addy