Database The first code is created.
You seem to give, otherwise you will get the following error.
A violation of a referential integrity constraint has occurred: a property values ββthat define referential constraints are incompatible between the main and dependent objects in the relation.
The principle is your Post object, a dependent Blog object.
when you try to attach your unallocated context, release POCO to the EF 4.1 DBContext context:
using (TransactionScope scope = new TransactionScope()) using (ITAMdbContext db = new ITAMdbContext()) { db.Entry(post).State = System.Data.EntityState.Unchanged;
This error is resolved ..
using (TransactionScope scope = new TransactionScope()) using (ITAMdbContext db = new ITAMdbContext()) { post.BlogId = post.Blog.BlogId;
do it your own way if your POCO objects are not automatically generated.
the reason you set the post to Unchanged, and then set it to Modified, because the first property is Entry (). State set on the object will cascade the same state to all child objects! horrible, but it seems to work. then when you call it again, it only changes the post object. This stops the children that are being modified or added.
EDIT: it is no longer required, it is made for you
Terry source share