CREATE TABLE [dbo].[Folder](
[FolderID] [int] IDENTITY(100,1) NOT NULL,
[FolderName] [nvarchar](100) NOT NULL,
[Description] [nvarchar](100) NULL,
[ParentFolderID] [int] NULL,
[IsDeleted] [bit] NULL CONSTRAINT [DF_Folder_IsDeleted] DEFAULT ((0)),
[OwnerUserID] [int] NULL,
[ModifiedDate] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[FolderID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
FolderID FolderName描述ParentFolderID IsDeleted OwnerUserID修改日期
100 T desc NULL False
101 T-C1 100
102 T-C2 100
103 T-C1-C1 101
104 T-C1-C2 101
105 T-C2-C1 102
106 T-C3 100
107 T-C1-C2-C1 104
Treeview格式的数据 用户输入:101 以分层格式检索所有记录,但删除ID为101且子项低于101的记录。需要Linq查询。
答案 0 :(得分:0)
尝试从这开始:
var lookup =
Folder
.Select(x => new
{
x.FolderID,
x.ParentFolderID,
})
.Where(x => x.FolderId != 101)
.ToLookup(x => x.ParentFolderID);
您可以使用lookup[100]
访问顶级文件夹。然后递归调用lookup[x.FolderID]
来遍历树。