Is there way to use Distinct in LINQ query syntax?
There is no Distinct()
method syntax in the language integrated query syntax. The closest you could do would be to move the current call:
var q = (from c in tbl
select c.TABLE_TYPE).Distinct();
The Distinct
extension method in LINQ does not have a query syntax equivalent.
See https://docs.microsoft.com/en-us/archive/blogs/charlie/linq-farm-using-distinct-and-avoiding-lambdas for additional information as to why.
(from c in tbl select c.TABLE_TYPE).Distinct();
VB has this functionality if you place the distinct after select.
You may capture HashSet and put where clause before select:
var hs = new HashSet<char>();
from c in "abcabcd"
where hs.Add(c)
select c;