Just tried out a solution: var nestedObjects = from row in data select new {row. PointA, row. PointB, Details = new { row.
Month, ExtraDetails = new { row. Time, row. Price } }} This is assuming that you have already got your data into data Group by If you want to group the Points together, you need 'Group By': var nestedObjects = from row in data group row by new { row.
PointA, row. PointB } into Points select new { Points = Points. Key, Details = from details in Points select new { row.
Month, ExtraDetails = new { row. Time, row. Price }} } A little more complicated - of course you might want to group by month as well, in which case, you need to follow the same pattern as for the Points bit.
Note, this will not create tables, because the group by doesn't quite do that, but it at least creates the structure for you.
Just tried out a solution: var nestedObjects = from row in data select new {row. PointA, row. PointB, Details = new { row.
Month, ExtraDetails = new { row. Time, row. Price } }}; This is assuming that you have already got your data into data.
Group by If you want to group the Points together, you need 'Group By': var nestedObjects = from row in data group row by new { row. PointA, row. PointB } into Points select new { Points = Points.
Key, Details = from details in Points select new { row. Month, ExtraDetails = new { row. Time, row.
Price }} }; A little more complicated - of course you might want to group by month as well, in which case, you need to follow the same pattern as for the Points bit. Note, this will not create tables, because the group by doesn't quite do that, but it at least creates the structure for you.
Assuming you got your classes defined for the objects you mentioned, and you have a constructor or properties so you can propery create the object in one line you could have a LINQ query returning a list of a POINTS. If would go something lik this : var res = from item in table.AsEnumerable() select new Points(){PointA = item"PointA"; PointB = item"PointB"; Details = from item2 in table.AsEnumberable() where item"PointA" = item2"PointA" and item"PointB" = item2"PointB" select new Details(){ month=item2"month", extraDetails = from item3 in table.AsEnumerable()... } }; At the end res will be a IEnumerable of Points I am sorry for the code, I am not at a computer with . NET 3.5 so I cannot write a proper testable query.
– Owen Davies Jun 10 '09 at 9:21 oK, now I really understood your question. Unfourtunately I don't know of any soltion that would not requrire nested linq queries. I will update my code to something like that.
– AlexDrenea Jun 10 '09 at 10:16.
I have a single table and I need to build a bunch of nested objects based on the single table. I want to avoid having loads of loops and if statements, so should be able to use linq to do this. But its beyond my linq experience.
Any help would be great.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.