Question

I have a many to many relationships in my dataBase, so I have three tables, TableA, TableB and TableAB. TableAB only has the primary key of the tableA and the primary key of the tableB.

When I create my edmx from the data base, I don't have the entity of the tableAB. I would like to delete the register of the tableAB, but not delete the registers of the tableA and tableB.

How can I do this operation with the self tracking entities?

I have the following options:

myContext.tableA.Attach(myTableARecord);
myTableARecord.TableBRecord.Remove(myTableARecord.myTableBRecord[0]);
miContexto.SaveChanges();

This works.

But if I use applyChanges instead of attach, then it does not work. Which is the difference between applyChanges of the STE and the Attach method of the context?

Thanks.

Was it helpful?

Solution

Attach takes a entity that has been disconnected from an ObjectGraph and attaches it to the ObjectGraph.

AcceptChanges commits the changes within the entity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top