有没有办法在LINQ查询语法中使用Distinct? [英] Is there way to use Distinct in LINQ query syntax?

查看:99
本文介绍了有没有办法在LINQ查询语法中使用Distinct?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以重写:

var tbl = ds.TABLES;
var q = from c in tbl
        select c.TABLE_TYPE;
string s = "";
foreach (var item in q.Distinct())
{
    s += "[" + item + "]";
}        
MessageBox.Show(s);

这样Distinct()调用就在LINQ查询中了吗?

So that the Distinct() call is in the LINQ query?

推荐答案

LINQ中的Distinct扩展方法没有等效的查询语法.

The Distinct extension method in LINQ does not have a query syntax equivalent.

请参见 https://docs.microsoft.com/zh-CN/archive/blogs/charlie/linq-farm-using-distinct-and-avoiding-lambdas 了解有关原因的更多信息.

See https://docs.microsoft.com/en-us/archive/blogs/charlie/linq-farm-using-distinct-and-avoiding-lambdas for additional information as to why.

这篇关于有没有办法在LINQ查询语法中使用Distinct?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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