C# group by 不起作用
我的 C# 代码在示例中到处都有一些问题,他们像我一样这样做,但不知怎的,我会得到一些错误
编译器在 g.Datum 处说他不知道 Datum
,在“返回查询”时他说 - 无法转换
,有一个明确的转换
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.Datum
select n).Count()
select new StatsistikObjekt() { Date1 = g.Datum, number1 = number });
return query;
希望你能帮助我=)
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.Datum
select n).Count()
select new StatsistikObjekt() { Date1 = g.Datum, number1 = number });
return query;
hope you can help me =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
范围变量
g
的类型是group,它确实没有Datum
值。您可以轻松地修复这个问题,给定您的分组(使用 Datum 作为键),并且通过仅计算组的大小来使您的查询也更简单:
至于返回值 - 我们可以'在这方面并不能真正帮助您,因为我们不知道您要返回的返回类型。
The type of the range variable
g
is the group, which indeed doesn't have aDatum
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: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.
尝试使用
g.Key
而不是g.Datum
Try
g.Key
instead ofg.Datum