开发者

Intellisense in linq projection after group by

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 monthlyState开发者_开发问答ments = 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 
                                  };


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜