group by 后 linq 投影中的智能感知

发布于 2024-11-25 20:14:56 字数 1107 浏览 2 评论 0原文

我有一个 Collection;语句 其中

public interface IStatements
{
    IDocuments Documents { get; set; }
    string StatementDate { get; set; }
} 
public class Documents : IDocuments
{
    public string Date { get; set; }
    public string Url { get; set; }
}

我想对 StatementDate 执行分组,然后进行投影。 当预测该组是否有多个声明时,我想将他们的声明日期合并为 1。问题是在 groupby 之后我没有得到 Intellisense

 var monthlyStatements = from mStatement in statements
             orderby mStatement.StatementDate descending
             group mStatement by mStatement.StatementDate;

我尝试了以下代码

var monthlyStatements = from mStatement in statements
           orderby mStatement.StatementDate descending
           group mStatement by mStatement.StatementDate
                   into msStatement
                         select new 
                                  {
                                   StatementDate = 
                                    mStatement.Documents.Date.,//no Intellisense 
                                  };

I have a Collection<IStatements> statements which has

public interface IStatements
{
    IDocuments Documents { get; set; }
    string StatementDate { get; set; }
} 
public class Documents : IDocuments
{
    public string Date { get; set; }
    public string Url { get; set; }
}

I would like to perform a group by on StatementDate and then do a projection.
When projecting if the group has more then one statement then I would like to club their statement date into 1. The problem is that I don't get Intellisense after groupby

 var monthlyStatements = from mStatement in statements
             orderby mStatement.StatementDate descending
             group mStatement by mStatement.StatementDate;

I have tried following code

var monthlyStatements = from mStatement in statements
           orderby mStatement.StatementDate descending
           group mStatement by mStatement.StatementDate
                   into msStatement
                         select new 
                                  {
                                   StatementDate = 
                                    mStatement.Documents.Date.,//no Intellisense 
                                  };

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

非要怀念 2024-12-02 20:14:56

msStatement 将是IStatements分组,而不是单个 IStatements。 ,您可以用它做两件事:

  • 获取 Key 属性(这将是对帐单日期)
  • 获取组的内容(每一个都将是一个 IStatements

因此 不过,不太清楚您要对多个 IStatements 做什么。

您不再获得 dStatementDate 的原因是您正在使用查询延续;唯一剩下的就是分组。幸运的是,这里无关紧要,因为您可以从密钥中获取报表日期;您可以完全删除“let”子句。

msStatement is going to be a grouping of IStatements, not a single IStatements. So you can do two things with it:

  • Get the Key property (which will be the statement date)
  • Get the contents of the group (which will each be an IStatements)

It's not really clear what you're trying to do with the multiple IStatements though.

The reason you haven't got dStatementDate any more is because you're using a query continuation; the only thing left is the grouping. Fortunately it's irrelevant here as you can get the statement date from the key; you can remove your "let" clause completely.

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