DeleteBasicProtocolRecursively
private void DeleteBasicProtocolRecursively(ModelContainer container, string parentId, string strProtocolId)
{
#region BasicProtocolStructure
var nodes = from node in container.BasicProtocolStructures
where node.Pid == parentId
select node;
if (nodes != null && nodes.Count<BasicProtocolStructure>() > 0)
{
foreach (BasicProtocolStructure ps in nodes)
{
container.BasicProtocolStructures.DeleteObject(ps);
DeleteBasicProtocolRecursively(container, ps.Id, strProtocolId);
}
}
#endregion
#region BasicProtocolItem
var sItems = from item in container.BasicProtocolItems
where item.Pid == parentId
&& item.ProtocolId == strProtocolId
select item;
if (sItems != null && sItems.Count<BasicProtocolItem>() > 0)
{
foreach (BasicProtocolItem bpi in sItems)
{
container.BasicProtocolItems.DeleteObject(bpi);
}
}
#endregion
}
DeleteBasicProtocolRecursivelyByProtocolId
//Attention: This method should never set as Operation Contract
public int DeleteBasicProtocolRecursivelyByProtocolId()
{
ModelContainer container = ModelContext.Container;
if (container == null)
{
return -1;
}
var BasicProtocolWantToDelete = from c in container.BasicProtocolStructures
where c.Id != "53ebc489-29e8-4e17-9cd1-8f7b485c3334"
&& c.Id != "62d93b36-5c2e-426c-912a-5fa103bca694"
&& c.Id != "c632d27b-48c1-4566-aef7-2e7d5529a0d2"
&& c.Pid == null
select c;
if (BasicProtocolWantToDelete != null && BasicProtocolWantToDelete.Count<BasicProtocolStructure>() > 0)
{
foreach (BasicProtocolStructure bps in BasicProtocolWantToDelete)
{
this.DeleteBasicProtocolRecursively(container, bps.Id, bps.Id);
container.BasicProtocolStructures.DeleteObject(bps);
}
}
return ModelContext.SaveChanges();
}