I need to group the table according to the Month in the table.
The query goes this way:
var query =
from a in db.Dates
from b in db.Facts
where a.Count_Key == b.Date_key
select new
{
a.Month,
b.Fact_key
};
From this query I try to group by Month
query = query.GroupBy(x => x.Month);
Grid1.DataSource = query;
Grid1.DataBind();
Then I get the following error which says:
Cannot implicitly convert IGrouping
int ? into IQueryable
You can do this:
The problem is caused because the
var queryis implicitly inferred from its usage. Thequeryis of typeIQueryable<SomeAnonymousType>and theGroupBymethod returns anIQueryable<IGrouping<int?, SomeAnonymousType>>. Those are simply two different types.