本文介绍了复制分层数据的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用Entity Framework 5,C#和Visual Studio 2012来完成一个项目。该项目的一个SQL Server表将数据保持在层次结构中;它的名字是员工。 Employee表被视为员工树林(员工组)。每个树都以一行开头,其ParentId列值为null,其后代行具有非null ParentId值。 员工加入或离开树时(组) ),该树的所有行都设置为非活动(0)并变为非活动树,同时从旧的非活动树复制将IsActive列设置为1的新树。新树的所有行肯定都将ParentId列设置为新值,因为新行的EmployeeId主标识密钥是由SQL Server创建的。请参阅下面的详细信息。 我想使用Entity Framework和C#代码为这样一个新的行树进行深层复制。实现这一目标的最佳方法是什么?提前谢谢。 详细信息 复制新行树之前的员工表: EmployeeId FirstName LastName ParentId IsActive 1 aaa bbb null 1 2 ccc ddd 1 1 5 kkk lll 1 1 3 eee fff 2 1 4 ggg hhh 2 1 6 mmm nnn 5 1 7 lim wer null 1 8 kie aol 7 1 9 hfj nvu 8 1 当名为ooo ppp的员工加入其根EmployeeId的树时7,表格更新如下,注意最后4行,看看我想要的行复制深度。 EmployeeId FirstName La stName ParentId IsActive 1 aaa bbb null 1 2 ccc ddd 1 1 5 kkk lll 1 1 3 eee fff 2 1 4 ggg hhh 2 1 6 mmm nnn 5 1 7 lim wer null 0 8 kie aol 7 0 9 hfj nvu 8 0 10 lim wer null 1 11 kie aol 10 1 12 hfj nvu 11 1 13 ooo ppp 11 1 解决方案 I am using Entity Framework 5, C# and Visual Studio 2012 to do a project. One of SQL Server tables of that project keeps data in hierarchical structure; its name is Employee. The Employee table is considered as a forest of employee trees (employee groups). Each tree starts with a row whose ParentId column value is null, and its descendant rows have non-null ParentId values.When an employee joins or leaves a tree (group), all rows of that tree are set to inactive (0) and becomes inactive tree, and at the same time a new tree which has IsActive columns being set to 1 is copied from the old inactive tree . All the rows of the new tree are definitely have ParentId columns set to new values because EmployeeId primary identity keys for new rows are created by SQL Server. See details below.I'd like to use Entity Framework and C# codes to make deep copy for such a new tree of rows. What is the best way to achieve that? Thank you in advance.DetailsEmployee table before a new tree of rows is copied:EmployeeId FirstName LastName ParentId IsActive1 aaa bbb null 12 ccc ddd 1 15 kkk lll 1 13 eee fff 2 14 ggg hhh 2 16 mmm nnn 5 17 lim wer null 18 kie aol 7 19 hfj nvu 8 1When employee named "ooo ppp" joins the tree whose root EmployeeId of 7, the table is updated as follows, pay attention to the last 4 rows to see how deep copied rows I want.EmployeeId FirstName LastName ParentId IsActive 1 aaa bbb null 1 2 ccc ddd 1 1 5 kkk lll 1 1 3 eee fff 2 1 4 ggg hhh 2 1 6 mmm nnn 5 1 7 lim wer null 0 8 kie aol 7 0 9 hfj nvu 8 0 10 lim wer null 1 11 kie aol 10 1 12 hfj nvu 11 1 13 ooo ppp 11 1 解决方案 这篇关于复制分层数据的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 03:50