Does anybody know how to remove an object together with every entity that is connected to it?
As an example, I have the following tables: Products, Category, ProductCategory, and productDetails; ProductCategory joins the Product and Category data.
From what I've read in http://msdn.microsoft.com/en-us/library/bb738580.aspx,
Deleting the parent object also deletes all the child objects in the constrained relationship. This result is the same as enabling the
CascadeDeleteproperty on the association for the relationship.
Using this code, I
Product productObj = this.ObjectContext.Product.Where(p => p.ProductID.Equals(productID)).First(); if (!productObj.ProductCategory.IsLoaded) productObj.ProductCategory.Load(); if (!productObj.ProductDetails.IsLoaded) productObj.ProductDetails.Load(); //my own methods. base.Delete(productObj); base.SaveAllObjectChanges();
But I'm encountering a mistake on
A relationship is being added or deleted from an
AssociationSet'FK_ProductCategory_Product'. With cardinality constraints, a corresponding 'ProductCategory' must also be added or deleted.
I appreciate the response. My issue has been resolved. EDMX employs the same cascade. I'm responding to my own query for clarification. :)
We must include
at two places in the EDMX file