Sunday, 15 March 2015

c# - Linq Groupby Sum a nested observable collection -


I need some help gathering data in my collection

RRRPPS class < Pre> /// & lt; Summary & gt; / RRV response /// & lt; / Summary & gt; Public category RRVResponse {/// & lt; Summary & gt; Starts a new instance of ///; & Lt; Cref = "RRVResponse" /> See Classroom. /// & lt; / Summary & gt; Public RRRPS Pensions () {this.BoDPoints = New Observation Collection & lt; BidofferPoint & gt; (); } /// & lt; Summary & gt; Sets or sets the /// ID /// & lt; / Summary & gt; Public string id {get; Set; } /// & lt; Summary & gt; /// Date or set the message /// & lt; / Summary & gt; Public DateTime Message-Date {Receive; Set; } /// & lt; Summary & gt; /// BOD Issuing or Sets /// & lt; / Summary & gt; Public Supervision Collection & lt; BidofferPoint & gt; BoPoints {receive; Set; }}

implementation, var responses = new supervision collection & lt; RRVResponse & gt; (); // .... Load responses ... // ... // ...

The count of responses is 5, so I have the responsibility of choosing the 5 responsibilities BoPoints.

  are BOD digits, /// & lt; Summary & gt; /// bid proposal point /// & lt; / Summary & gt; Public class bidofferpoint {/// & lt; Summary & gt; /// sets or sets the date /// & lt; / Summary & gt; Public Date Time Date {Received; Set; } /// & lt; Summary & gt; Sets or sets time /// /// & lt; / Summary & gt; Public string time {received; Set; } /// & lt; Summary & gt; /// sets or sets the amount /// & lt; / Summary & gt; Public decimal quantity {received; Set; } /// & lt; Summary & gt; Sets or sets the /// value /// & lt; / Summary & gt; Public decimal value {received; Set; }}   

sample,

  overview collection archive - 1 2013-06-21 00:00 100 10 2013-06-21 00:15 120 15 2013-06-21 00:30 150 9 Component Collection Board - 2  
  2013-06-21 00:00 Observation Collection Collection - 1 2013 -06-21 00:00 100 10 2013- 06-21 00:15 120 15 2013-06-21 00:30 150 9 40 1 2013-06-21 00:15 10 0.5 2013-06-21 00:30 11 0.1   

Overview Collection Board - 3

  2013-06-15 00:00 100 10 2013-06-15 00:15 120 15 2013-06 -15 00:30 150 9  

I want to group by date, then gross hours and volume throughout the collection, so in the above example, for the 21-06-2013 at 00:00 all the numbers Should be collected, all editions for the 21-06-2013 should be collected for hours 00:15.

What is the best way to use Linq?

You can use SelectMany to collect objects and You can add them to the group later:

  var results = reactions. Select (R = & gt; R. PoPoint Points) .GroupBy (p = & gt; p.Date). Select (date = & gt; new {Date = Date of Date, EntriesByTime = byDate .GroupBy (p = & gt; p.Time.) Select (byTime => New {Time = Time Time. Total Volomum = Bitime. Sum (p = & gt; P. Volume)}}});   

You can use the following loop (like to produce total volume)

  foreach (as a result of the date) {Console.WriteLine ("Date" by date date); foreign currency (by date dated by intercity) {console.lightline ("total quantity for time" + timetime.time + ":" + time-merge merger);}}    

No comments:

Post a Comment