group by 后 linq 投影中的智能感知
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
msStatement
将是IStatements
的分组,而不是单个
IStatements
。 ,您可以用它做两件事:Key
属性(这将是对帐单日期)IStatements
)因此 不过,不太清楚您要对多个
IStatements
做什么。您不再获得
dStatementDate
的原因是您正在使用查询延续;唯一剩下的就是分组。幸运的是,这里无关紧要,因为您可以从密钥中获取报表日期;您可以完全删除“let”子句。msStatement
is going to be a grouping ofIStatements
, not a singleIStatements
. So you can do two things with it:Key
property (which will be the statement date)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.