I've followed this post: LINQ group by property as a parameter to make a parametrizable query, and I'm now trying to do the same after a group by clause, but I can't properly define the group/or access the properties after it. Here is what I'm trying to achieve:
public Dictionary<string, float?> GetFundingByFilter<TKey>(Expression<Func<Object, TKey>> myGroupingProperty, Filter item)
{
int cntToBeSureThatTheQueryExecuteAtLeastOneTime = 0;
Dictionary<string, float?> countriesAndCount = new Dictionary<string, float?>();
using (var db = new fintechDbContext())
{
countriesAndCount = (from p in db.companyDBSET
join f in db.fundingDBSET on p.Company equals f.Company into d
from t in d.DefaultIfEmpty()
select new {p, t })
.GroupBy(myGroupingProperty)
.Select(r => new { Value = r.Key, Sum = r.Sum(d => d == null ? 0 : d.t.Amount) })
.OrderByDescending(y=>y.Sum)
.ToDictionary(v => v.Value.ToString(), v => v.Sum);
}
}
}
return countriesAndCount;
}
but d.t.Amount is no longer accessible in this case.