c# group by doesn't work
i have some problems with my c# code everywhere in the Examples they do it like me but somehow i gonna get some errors
Compiler says at g.Datum he doesn' t know Datum
and at "return query" he says - cannot convert
, there is a explicit convert
var query = (from p in dataContext.Untersuchungen
orderby p.Datum
group p by p.Datum into g
let number = (from n in dataContext.Untersuchungen
where n.Datum == g.Dat开发者_StackOverflowum
select n).Count()
select new StatsistikObjekt() { Date1 = g.Datum, number1 = number });
return query;
hope you can help me =)
The type of the range variable g
is the group, which indeed doesn't have a Datum
value.
You can fix that bit easily, given your grouping (which uses Datum
as the key)- and make your query simpler too by just counting the size of the group:
var query = (from p in dataContext.Untersuchungen
orderby p.Datum
group p by p.Datum into g
select new StatsistikObjekt() { Date1 = g.Key,
number1 = g.Count() });
As for the return value - we can't really help you on that one, as we don't know the return type you're trying to return.
Try
g.Key
instead of g.Datum
精彩评论