Thursday 15 April 2010

c# - Correct way to remove M:M in PLINQO? -


Suppose you have this table structure:

Patient -> Patient Tag -> Tag

A typical N: M relationship between patients and tags, pettag is both intermediate unit with FK. (Petit Id and Tag Id)

I want to remove a specific tag, I have its ID. I am doing this, but I would like to know if there is any better way, because this is the first method I am writing using Paleikuo, I do not want to start bad behavior from the beginning.

  (MyDataContext DC = Data Contextifier. Gate DataContact ()) using the {var option = new DataLead Option (); Options.LoadWith & lt; Paciente & gt; (P = & gt; P. privataglistlist); Options.LoadWith & lt; PacienteTag & gt; (Pt = & gt; pt.Tag); Dc.LoadOptions = Option; // Get deleted tag from DB Var tag = dc.Manager.Tag.GetByKey (idTag); // Remove every patient from the association Foreach (tag in pagente pac.PacienteList1) {// We need to retrieve it, we will not let us use the 'PAC' object. Var pax = dc.Manager.Paciente.GetByKey (pac.IdPaciente); Pax.TagList.Remove (tag); } // Now Tag D. Remove the manager.Tag.Dil (tag. TIGID); // Change the DC Submit (); }  

Thanks for any information on the topic.

About using a foreign key with cascading delete, then deleting tags and Take care to remove all references in the database. If you want to make sure that it was not in use, then you can check that no patients are connected before, although you may need to wrap it in a transaction, if other processes access to the same database Is doing. / P>


No comments:

Post a Comment