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

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.

Answers


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

AcceptChanges commits the changes within the entity.


Need Your Help

jQuery Tree Menu collapsing wrong way

jquery html

just one quick question about jQuery. I pretty new to this...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.