how can I read the query variable outside the if scope and use it further.
If (IsPaymentList)
{
var query = paymentList.GroupBy(
grp => (grp.GrouByField),
(GrouByField, paymentListgroup) => new
{
Key = GrouByField,
receiptAmount = paymentListgroup.Sum(fields => fields.PaymentAmount),
creditAccountnumber = paymentListgroup.Max(fields => fields.CreditAccountNumber),
bankAccountName = paymentListgroup.Max(fields => fields.AccountName),
bankName = paymentListgroup.Max(fields => fields.BankName),
payCurrency = paymentListgroup.Max(fields => fields.PaymentCurrencyID),
partnerServiceID = paymentListgroup.Max(fields => fields.PartnerServiceID),
});
}
Somebody please share your experience.
Thanks
You can declare the query variable as of type
IQueryable<IGrouping<typeOfKey,typeOfSelect>> query = null;outside the if and set it to null where the typeOfKey is the type of the grp.GrouByField property. Instead of selecting an anonymous type you have to create a new class that has the properties as needed like this:
After you create the class set the query to the generic type