Exemplo n.º 1
0
        /// <summary>
        /// 从文件夹节点所关联的文件集合中删除指定的文件
        /// </summary>
        /// <param name="folderDBPath"></param>
        /// <param name="fileIDs"></param>
        public void DeleteFilesOfFolderDB(String folderDBPath, List <int> fileIDs)
        {
            if (string.IsNullOrEmpty(folderDBPath) || fileIDs == null || fileIDs.Count == 0)
            {
                return;
            }
            using (InfocenterEntities context = new InfocenterEntities(EFConnectionString))
            {
                FolderDB folder = context.FolderDBs.FirstOrDefault(p => p.Path == folderDBPath);
                if (folder == null)
                {
                    return;
                }

                foreach (var file in folder.DiskFiles.ToList())
                {
                    if (fileIDs.IndexOf(file.ID) != -1)
                    {
                        //保证删除FolderAndFile记录
                        folder.DiskFiles.Remove(file);
                        //确保DiskFile删除
                        context.Entry(file).State = EntityState.Deleted;
                    }
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 接照路径删除指定的文件夹节点记录,其子节点数据不动(因为在更换节点
        /// 类型时,需要删除自己,但子节点是不能删除的)
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public int DeleteFolderDB(String path)
        {
            using (InfocenterEntities context = new InfocenterEntities(EFConnectionString))
            {
                var query = from folder in context.FolderDBs
                            where folder.Path == path
                            select folder;
                foreach (var folder in query)
                {
                    List <DiskFile> files = folder.DiskFiles.ToList();

                    foreach (var file in files)
                    {
                        context.Entry(file).State = EntityState.Deleted;
                    }

                    context.FolderDBs.Remove(folder);
                }
                return(context.SaveChanges());
            }
        }
        /// <summary>
        /// 按照路径删除FolderDB记录,如果它还有子记录,一并删除
        /// </summary>
        /// <param name="path"></param>
        public int DeleteFolderDBAndItsChildByPath(String path)
        {
            using (InfocenterEntities context = new InfocenterEntities(DALConfig.ConnectString))
            {
                var query = from folder in context.FolderDBs
                            where folder.Path.StartsWith(path)
                            select folder;
                foreach (var folder in query)
                {

                    List<DiskFile> files = folder.DiskFiles.ToList();

                    foreach (var file in files)
                    {
                        context.Entry(file).State = EntityState.Deleted;
                    }

                    context.FolderDBs.Remove(folder);
                }
                return context.SaveChanges();
            }
        }
        /// <summary>
        /// 从文件夹节点所关联的文件集合中删除指定的文件
        /// </summary>
        /// <param name="folderDBPath"></param>
        /// <param name="fileIDs"></param>
        public void DeleteFilesOfFolderDB(String folderDBPath, List<int> fileIDs)
        {
            if (string.IsNullOrEmpty(folderDBPath) || fileIDs == null || fileIDs.Count == 0)
            {
                return;
            }
            using (InfocenterEntities context = new InfocenterEntities(DALConfig.ConnectString))
            {
                FolderDB folder = context.FolderDBs.FirstOrDefault(p => p.Path == folderDBPath);
                if (folder == null)
                {
                    return;
                }

                foreach (var file in folder.DiskFiles.ToList())
                {
                    if (fileIDs.IndexOf(file.ID) != -1)
                    {
                        //保证删除FolderAndFile记录
                        folder.DiskFiles.Remove(file);
                        //确保DiskFile删除
                        context.Entry(file).State = EntityState.Deleted;
                    }

                }
                context.SaveChanges();
            }
        }