问题描述
嗨
我有以下数据,员工专栏视为父母,每名员工都有子女发票,每张发票都有发票详细信息作为子项。我已将此数据绑定到类列表中。现在我想使用LINQ从这个列表中创建层次结构列表
parent ---> child ---> subchild
员工 - - > Invoice ---> InvoiceDetails
列表数据:
员工发票InvoiceDetails jan feb Mar Apr
E1 I1 ID1 1 2 10 5
E1 I1 ID2 1 3 11 6
E1 I1 ID3 1 4 12 7
E1 I2 ID1 1 5 13 8
E1 I2 ID2 1 6 14 9
E1 I2 ID3 1 7 15 10
E2 I1 ID1 1 8 16 11
E2 I1 ID2 1 10 17 12
输出:
E1
- I1
------ ID1 1 2 10 5
---- --ID2 1 3 11 6
------ ID3 1 4 12 7
--I2
------ ID1 1 5 13 8
------ ID2 1 6 14 9
------ ID3 1 7 15 10
E2
- I1
----- ---- ID1 1 8 16 11
--------- ID2 1 10 17 12
我尝试了什么:
i已经试过2级标签,但是没有3级标签的想法
Hii have the below data , employee column consider as parent and each employee have invoice as child and each invoice have invoicedetails as subchild. i have binded this data into a list of class. now i want create hierarchy list from this list using LINQ
parent--->child--->subchild
Employee--->Invoice--->InvoiceDetails
List Data:
Employee invoice InvoiceDetails jan feb Mar Apr
E1 I1 ID1 1 2 10 5
E1 I1 ID2 1 3 11 6
E1 I1 ID3 1 4 12 7
E1 I2 ID1 1 5 13 8
E1 I2 ID2 1 6 14 9
E1 I2 ID3 1 7 15 10
E2 I1 ID1 1 8 16 11
E2 I1 ID2 1 10 17 12
Output :
E1
--I1
------ID1 1 2 10 5
------ID2 1 3 11 6
------ID3 1 4 12 7
--I2
------ID1 1 5 13 8
------ID2 1 6 14 9
------ID3 1 7 15 10
E2
--I1
---------ID1 1 8 16 11
---------ID2 1 10 17 12
What I have tried:
i have tried for 2 label of class but don't have idea for 3 label of hierarchy
var query = (from f in CustomerAllocation1
select new Field
{
FieldId = f.FieldId,
//EmployeeId = e.EmployeeId,
//InvoiceDetailsListRows.ForEach(z => z.ChildCount = items.Count(x => x.ParentId == z.Id)),
Children = (from c in CustomerAllocation
where c.FieldId == f.FieldId
select new Customer
{
FieldId = f.FieldId,
CustomerId = c.CustomerId,
jan = c.jan,
feb = c.feb,
mar= c.mar
april= c.april
}).tolist()
}).tolist()
推荐答案
这篇关于使用LINQ从列表创建一个层次结构列表类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!