On Jul 17, 5:39*pm, Seb <sebastianthegreat...@gmail.comwrote:
Quote:
I want to count activity in a given month. I'm trying to do so with
the linq code below however it reports:
Error * 1 * * * 'a' is inaccessible due to its protection level
>
* * * * * * * * var ActivityByMonths = from a in db.ActivityDatas
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *where a.BeginDateTime >= From && a.BeginDateTime <= To
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *where a.SubActivityId ==sat
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *group a by a.BeginDateTime.Month into mg
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *select new { a.BeginDateTime..Month, count = mg.Count() };
>
I want to select is the month number and the number of activities that
took place in that month.
Once you group 'a', it goes out of scope (since there's no single 'a'
associated with each group). The reason for the confusing error
message you get is probably that you have another 'a' in scope, which
is indeed inaccessible (most likely, a field with such name in a base
class). Instead, to access the value of the grouping key for each
group, use mg.Key:
* * * * * * * * var ActivityByMonths = from a in db.ActivityDatas
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *where
a.BeginDateTime >= From && a.BeginDateTime <= To
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *where
a.SubActivityId == sat
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *group a by
a.BeginDateTime.Month into mg
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *select new
{ mg.Key, count = mg.Count() };