如何编写分组依据的查询 [英] How to write a ling query for group by

查看:102
本文介绍了如何编写分组依据的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,


我有一个linq查询,用于分组,计数为> 1.

Linq查询是这样的:

Hi Friends,


I have a linq query which is used to group by, where the count is >1.

Linq query is like this:

var Serialnumberentered = from a in serialNumbercheck
                                        group a by new { a } into g
                                        where g.Count() > 1
                                        select new
                                        {
                                            g.Key
                                        };


当我在"serialNumbercheck"中输入空值时,上面的查询也正在计算空值.任何人都可以帮助我如何忽略空值.


when i entered empty values in "serialNumbercheck", the above query is taking the count of empty values also.can any one help me how can i ignore the empty values.

推荐答案

引入一个where 条款来删除empty 字符串,如下所示

Introduce a where clause to remove the empty strings as follows

var Serialnumberentered = from a in serialNumbercheck
//For .NET 2.0 and 3.5      where a == null ? false : a.Trim() != string.Empty  
//or                        where (a ?? "").Trim()!= string.Empty
                            where !string.IsNullOrWhiteSpace(a)
                            group a by new { a } into g
                            where g.Count() > 1
                            select new
                            {
                                g.Key
                            };


这篇关于如何编写分组依据的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆