Does anyone know how to delete an object and all objects associated with it.
For example, I have tables, Products, Category, ProductCategory and productDetails, productCategory combines a table of both Product and Category.
I read from http://msdn.microsoft.com/en-us/library/bb738580.aspx that
Deleting a parent also removes all child objects in a restricted relationship. This result will be the same as the CascadeDelete association property for the relationship.
I am using this code:
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();
But I get the error ObjectContext.SaveChanges(); Ie
The relationship is added or removed from the AssociationSet 'FK_ProductCategory_Product'. With capacity limitations, you must also add or remove the corresponding "ProductCategory".
source share