entity framework - EF 4 delete many to many object -


i trying delete object many many relationship refused worked.

the structure follows:

i have products table every product has excproducts

i trying delete excproduct following code

var objectcontx = new objectcontx(); var prod = objectcontx.products.where(p => p.productid == prodid).firstordefault(); var excprod = objectcontx.excproducts.where(exc => exc.excproductid == excprodid).firstordefault(); prod.excproducts.attach(excprod); prod.excproducts.remove(excprod); objectcontx.savechanges(); 

the excprod deleted database when getting product objectcontext has deleted excprod in it's list.

how delete objectcontext well?

if many many relationship has entity (e.g. if has payload) instance of entity must deleted. can done manually or using cascaded delete (see option in property window while standing on relationship in edmx designer).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -