C# group by 不起作用

发布于 2024-11-07 05:14:38 字数 599 浏览 3 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溇涏 2024-11-14 05:14:38

范围变量g的类型是group,它确实没有Datum值。

您可以轻松地修复这个问题,给定您的分组(使用 Datum 作为键),并且通过仅计算组的大小来使您的查询也更简单:

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() });

至于返回值 - 我们可以'在这方面并不能真正帮助您,因为我们不知道您要返回的返回类型。

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.

入画浅相思 2024-11-14 05:14:38

尝试使用

g.Key 而不是 g.Datum

Try

g.Key instead of g.Datum

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文