Hello everybody,
I try to get a list from a dataview containing a sum and grouped by some fields.
- DataView view = _objManager.ACCOUNTS.DefaultView;
- // Set RowStateFilter to display the current rows.
- view.RowStateFilter = DataViewRowState.CurrentRows;
- var res = ((DataTable)view.Table)
- .AsEnumerable()
- .GroupBy(row => new { ID = row.Field<long?>("ID"), ELEM = row.Field<string>("ELEM") })
- .Select(sel => new
- {
- NAME = sel.First()["NAME"],
- ID = sel.First()["ID"],
- IBAN = sel.First()["IBAN"],
- BIC = sel.First()["BIC"],
- INFO = sel.First()["INFO"],
- AMOUNT= sel.Sum(s => sel.Sum()["AMOUNT"]) //doesn't work
- }).ToList();
But the sum doesn't compile.
Do you have and idea ?
Thanks a lot in advance.
Eric

Farhan AhmedRank #73 · 25K reputationPosted Aug 1, 2020, 1:53 AM EDT
Ashutosh GuptaRank #805 · 2.9K reputationPosted Aug 1, 2020, 1:56 AM EDT
Laxmidhar SahooRank #383 · 6.6K reputationPosted Aug 1, 2020, 3:34 AM EDT
Jayakumar Vinayagam34 reputationPosted Aug 5, 2020, 5:11 AM EDT
.GroupBy(x => new { Id = x.Field
.Select(x => new {
Id = x.Key.Id,
Name = x.FirstOrDefault().Field
IBan = x.FirstOrDefault().Field
Bic = x.FirstOrDefault().Field
Info = x.FirstOrDefault().Field
Elem = x.Key.Elem,
Amount = x.Sum(y=>y.Field
})
.ToList();
Rajesh GamiRank #30 · 41.5K reputationPosted Aug 7, 2020, 2:01 AM EDT
Darshan ShahRank #1,135 · 1.6K reputationPosted Aug 1, 2020, 2:10 AM EDT