entity framework 4.0 with STEs: how to delete a many to may relationship without delete registers

StackOverflow https://stackoverflow.com/questions/12323964

Domanda

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.

È stato utile?

Soluzione

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

AcceptChanges commits the changes within the entity.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top