var groups = from t in DataSet1.TotalRevenuwByMonth
where t.totalcategory.Equals(Helpers.TotalCategory.PNEWBUSINESS)
group t by t.totalcategory into g
select new { totalcategory= t.totalcategory,
productFamily=t.productFamily
sum1=g.sum(a=>a.field1),
sum2=g.sum(b=>b.field2)};
Cheers,
Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
Error 1 'System.Linq.IGrouping<int,AnonymousType#1>' does not contain a definition for 'rental_rc' and no extension method 'rental_rc' accepting a first argument of type 'System.Linq.IGrouping<int,AnonymousType#1>'
could be found (are you missing a using directive or an assembly reference?) C:\Users\.....
Ohh.. My appologies... You have to group by both prperties to access it, thn you can access it as k.key.Renta, k.key.Category.
I think you have to use LINQ rather than the extension.
var groups = from t in DataSet1.TotalRevenuwByMonth
where t.totalcategory.Equals(Helpers.TotalCategory.PNEWBUSINESS)
group t by t.totalcategory into g
select new { totalcategory= t.totalcategory,
productFamily=t.productFamily
sum1=g.sum(a=>a.field1),
sum2=g.sum(b=>b.field2)};
Cheers,
Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
var groubyList = empList.GroupBy(q =>q.DOB);
foreach (var employees in groubyList)
{
var DOB= employees.Key;
foreach (var empl in employees)
{
var ID=empl.ID,
var FName=empl.Name;
}
}
Cheers,
Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
micnie2020
Member
306 Points
524 Posts
DataSet .Select and .GroupBy
Apr 26, 2012 10:11 AM|LINK
Hi All,
I having problem on .Select() bold section:-
DataSet1.TotalRevenueByMonthRow totalPendingNew = (DataSet1.TotalRevenueByMonthRow)dataSet1.TotalRevenueByMonth.Where(p => p.totalcategory.Equals(Helpers.TotalCategory.PNEWBUSINESS)).Select(k=>k.totalcategory,productFamily,sum(field1),sum(field2)).GroupBy(p=>p.totalcategory, p=>p.productfamily).FirstOrDefault();
Can anyone help me with this?
Thank you.
Regards,
Micheale
Neil_Knight
Member
260 Points
59 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 10:29 AM|LINK
I think the answer to your question is within the formatting. In your GroupBy, you are declaring a p for each attribute e.g.
If you try the same prinicipals with your Select, does this resolve it?
gopakumar.r
Participant
959 Points
193 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 10:40 AM|LINK
Try using the below code for select
var groups = from t in DataSet1.TotalRevenuwByMonth where t.totalcategory.Equals(Helpers.TotalCategory.PNEWBUSINESS) group t by t.totalcategory into g select new { totalcategory= t.totalcategory, productFamily=t.productFamily sum1=g.sum(a=>a.field1), sum2=g.sum(b=>b.field2)};Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
micnie2020
Member
306 Points
524 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 10:44 AM|LINK
Thank you for your kind reply.
I manage to done untill here:-
dataSet1.TotalRevenueByMonth.Select(k =>new { k.totalcategory, k.rental_rc }).GroupBy(p => p.totalcategory).Sum(p => p.rental_rc).Where(p => p.totalcategory.Equals(Helpers.TotalCategory.PNEWBUSINESS)).FirstOrDefault();
But got error:-
Error 1 'System.Linq.IGrouping<int,AnonymousType#1>' does not contain a definition for 'rental_rc' and no extension method 'rental_rc' accepting a first argument of type 'System.Linq.IGrouping<int,AnonymousType#1>' could be found (are you missing a using directive or an assembly reference?) C:\Users\.....
Please advise
gopakumar.r
Participant
959 Points
193 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 12:14 PM|LINK
try the below
dataSet1.TotalRevenueByMonth.Select(k =>new {Category=k.totalcategory,Rental=k.rental_rc }).GroupBy(p => p.Category).Sum(k => k.Rental).Where(p => p.Key.Equals(Helpers.TotalCategory.PNEWBUSINESS)).FirstOrDefault();Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
micnie2020
Member
306 Points
524 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 12:54 PM|LINK
Hi Sir,
It's show error on .Sum(k => k.Rental), only got k.Key
Please advise.
Thank you.
gopakumar.r
Participant
959 Points
193 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 01:28 PM|LINK
Ohh.. My appologies... You have to group by both prperties to access it, thn you can access it as k.key.Renta, k.key.Category.
I think you have to use LINQ rather than the extension.
var groups = from t in DataSet1.TotalRevenuwByMonth where t.totalcategory.Equals(Helpers.TotalCategory.PNEWBUSINESS) group t by t.totalcategory into g select new { totalcategory= t.totalcategory, productFamily=t.productFamily sum1=g.sum(a=>a.field1), sum2=g.sum(b=>b.field2)};Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
gopakumar.r
Participant
959 Points
193 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 01:34 PM|LINK
Here is an example how you can use the group by
var groubyList = empList.GroupBy(q =>q.DOB); foreach (var employees in groubyList) { var DOB= employees.Key; foreach (var empl in employees) { var ID=empl.ID, var FName=empl.Name; } }Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
micnie2020
Member
306 Points
524 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 01:40 PM|LINK
Hi Sir,
I need it to be in this format:- Is refer to DataRow
DataSet1.TotalRevenueByMonthRow totalPendingNew = (DataSet1.TotalRevenueByMonthRow)dataSet1.TotalRevenueByMonth.Select(p => new { p.totalcategory, p.training_rc }).GroupBy(x => new { x.totalcategory }).FirstOrDefault();
When i try to put Sum(training_rc). It's will not work.
Please advise.
Thank you.
gopakumar.r
Participant
959 Points
193 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 02:27 PM|LINK
What is the error you are getting?
Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |