Why, in PLINQO, is the fo开发者_JAVA百科llowing valid;
parent.ManyToManyChildList.Add(child)
context.SubmitChanges();
But the following is not?
parent.ManyTomanyChildList.Remove(child)
context.SumbmitChanges();
Using Remove(), attempts to set the parent FK part of the many-to-many table's PK to null. Is the only way to delete the relationship using PLINQO via this?
context.ManyToManyEntity.DeleteOnSubmit(entity)
context.SubmitChanges();
Opening the .DBML (in the xml editor) and setting the foreign key association.DeleteOnNull="true' on the many-to-many table's parent-side of the foreign key fixed this.
<Table Name="dbo.ParentChild" Member="ParentChild">
<Type Name="ParentChild">
<Column Name="ParentId" Storage="_parentId" Type="System.Int32" DbType="int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="ChildId" Storage="_childId" Type="System.Int32" DbType="int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Association Name="Child_ParentChild" Member="Child" Storage="_child" ThisKey="ChildId" Type="Child" IsForeignKey="true" DeleteOnNull="false" />
<Association Name="Parent_ParentChild" Member="Parent" Storage="_parent" ThisKey="ParentId" Type="Parent" IsForeignKey="true" DeleteOnNull="true" />
</Type>
</Table>
This is explained here; http://blogs.msdn.com/b/bethmassi/archive/2007/10/02/linq-to-sql-and-one-to-many-relationships.aspx
精彩评论