zoukankan      html  css  js  c++  java
  • 递归删除树结构数据

    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();

            }

  • 相关阅读:
    用户模板和用户场景
    人月神话阅读笔记02
    人月神话阅读笔记01
    软件工程周总结07
    NABCD
    软件工程周总结06
    软件工程周总结05
    tomcat端口被占用
    SQLyog出现2003错
    一维最大子数组和(续)
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2287668.html
Copyright © 2011-2022 走看看