使用Linq获取项目数 [英] Get a count of items with Linq
本文介绍了使用Linq获取项目数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Linq查询中获取具有相同描述的商品的数量.我的查询看起来像这样
I am trying to get a count of items in a Linq query for items with the same description. My query looks kind of like this
var dataSource = (from t in context.Tags
select new
{
Name = t.Description,
Count = //I dont know how to do this :/
});
任何帮助都会很棒,
谢谢
Any help would be great,
Thanks
推荐答案
您可以为此使用分组.请参阅: http://msdn.microsoft.com/en-us/library/bb896250.aspx [^ ]
例如:
You can use grouping for that. See: http://msdn.microsoft.com/en-us/library/bb896250.aspx[^]
For example:
var dataSource = (from t in context.Tags
group t by t.Description into t_group
select new
{
Name = t_group.Key,
Count = t_group.Count()
});
这篇关于使用Linq获取项目数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文