【问题标题】:Intellisense in linq projection after group by分组后的 linq 投影中的智能感知
【发布时间】:2011-07-22 14:46:24
【问题描述】:

我有一个Collection<IStatements> statements

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

【问题讨论】:

    标签: linq group-by linq-to-objects projection


    【解决方案1】:

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

    • 获取Key 属性(即声明日期)
    • 获取组的内容(每个都是IStatements

    不过,目前还不清楚你想用多个 IStatements 做什么。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      • 2020-09-06
      相关资源
      最近更新 更多