假设你有这样的表结构:在PLINQO中删除M:M的正确方法是什么?
病人 - > PatientTag - >标签
一个典型的N:患者和标签米之间的关系,PatientTag是既FKS中间实体。 (PatientId和TagId)。
我想删除一个特定的标签,我有它的ID。我这样做,但我想知道是否有更好的方法,因为这是我使用PLINQO编写的第一种方法,我不想从一开始就创建不好的做法。
using (MyDataContext dc = DataContextFactory.GetDataContext())
{
var options = new DataLoadOptions();
options.LoadWith<Paciente>(p => p.PacienteTagList);
options.LoadWith<PacienteTag>(pt => pt.Tag);
dc.LoadOptions = options;
// Get the Tag we're going to remove from the DB.
var tag = dc.Manager.Tag.GetByKey(idTag);
// Remove each patient from the association.
foreach (Paciente pac in tag.PacienteList1)
{
// we need to retrieve it, won’t let us use the ‘pac’ object.
var pax = dc.Manager.Paciente.GetByKey(pac.IdPaciente);
pax.TagList.Remove(tag);
}
// now remove the tag
dc.Manager.Tag.Delete(tag.TagId);
// And commit the changes
dc.SubmitChanges();
}
感谢您对该主题的任何见解。
我忘记了这个基本想法:)谢谢。 – 2009-12-01 15:37:09