linq hierarchy problem

Posted by Pratik on Stack Overflow See other posts from Stack Overflow or by Pratik
Published on 2010-12-23T08:33:59Z Indexed on 2010/12/29 12:53 UTC
Read the original article Hit count: 347

Filed under:
|
|
|
|

I reterive a result from sql server as

ProjectDetailID,ProjectID,ParentID,...,C1,C2,C3,...

where C1 implies(=>) companyOne, C2=>CompanyTwo ... etc and dynamically can have 'n' companies

For time being lets consider only 3 companies, So I get :

ProjectDetailID,ProjectID,ParentID,C1,C2,C3
10,1,0,NULL,NULL,NULL
10,2,1,NULL,NULL,NULL
10,3,2,90,NULL,NULL
10,4,2,NULL,60,NULL
10,10,1,70,NULL,NULL
10,5,10,20,40,NULL
10,13,2,NULL,NULL,NULL

I want from this following result using LINQ (C#)

ProjectDetailID,ProjectID,ParentID,C1,C2,C3
10,1,0,180,100,NULL
10,2,1,90,60,NULL
10,3,2,90,NULL,NULL
10,4,2,NULL,60,NULL
10,10,1,90,40,NULL
10,5,10,20,40,NULL
10,13,2,NULL,NULL,NULL

The problem is that at parent level i have null value for a company but at its child i have some value, which i keep on adding and have placed that in parent corresponding to that company only.

I am not getting from where to start. Please share your ideas. And i am looking to do this in LINQ using C#

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET