score:14
Accepted answer
You need a where, not a select:
var qry = from m in context.Collections
group m by new { m.city, m.name } into grp
where grp.Count() > 1
select grp.Key;
score:0
Building on @Jon Skeet's answer with a "one liner" alternative that returns the duplicate values, not just the keys:
var duplicates = db.Collections.GroupBy(m => new { m.city, m.name })
.Where(a => a.Count() > 1)
.SelectMany(a => a.ToList());
Source: stackoverflow.com
Related Articles
- Finding duplicate row using Linq
- Finding duplicate values in row(s) in different tables using linq vb.net
- Convert string[] to int[] in one line of code using LINQ
- Finding first index of element that matches a condition using LINQ
- How to find duplicate record using Linq from DataTable
- Finding Consecutive Items in List using Linq
- Left outer join using LINQ -- understanding the code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Using LINQ to remove any value that is a duplicate
- Avoiding code repetition when using LINQ
- Using LINQ to delete an element from a ObservableCollection Source
- LINQ Source Code Available
- Duplicate rows when using orderby, Skip() and Take() with LINQ
- Finding combinations of a grouped list using LINQ in c#
- Finding common components using LINQ
- How can I write the following code more elegantly using LINQ query syntax?
- Finding objects which contains at least all elements from subset using RavenDB and LINQ
- Merge duplicate data without affecting others in LINQ code
- How can I code an outer join using LINQ and EF6?
- MVC Controller: Using LINQ to check for duplicate value already existing in table before Save?
- How to remove duplicate combinations from a List<string> using LINQ
- C# .Net 3.5 Code to replace a file extension using LINQ
- Trying to understand LINQ code using c#
- Retrieve bool result by using LinQ code
- Comparing List<String> with duplicate information using Linq
- Finding common columns from two datatable and using those for Join condition in LINQ
- Using Linq to group by multiple columns in a list and mark all duplicate items
- Trouble finding duplicates using LINQ expressions
- creating Linq to sqlite dbml from DbLinq source code
- read icollection data using LINQ in C# code
- Filtering EfCore DbSet with expression causing exception
- Adapting Linq Entity objects to Domain objects
- LINQ: Trying to pull data and join 3 tables where relationships differ (one-to-one, one-to-many)
- ContainsValue VB
- Get the result of two compared list and change an attribut in list deponding on the result using LINQ
- Why Enumerable.OrderBy<TSource, TKey> Method works faster when it doesn't use Comparer
- Finding duplicates in IGrouping Using linq
- How does LINQ Where() clause in .Net work?
- Group By in LINQ with a particular column
- How to concatenate two column values inside List?
- Quick Question: C# Linq "Single" statement vs "for" loop
- Sequence has no matching elements (LET CLAUSE)
- C# - Get property of Attribute with Linq
- Dynamic SQL to LINQ Entity Framework
- LINQ Left join on condition having 'OR'
- How do I sort a Dictionary<K, Dictionary<K,V>> using LINQ operations?
- Merge 2 lists based on one property and concatenate other properties
- Convert this query to Linq to SQL
- using equal and not equal in a linq join
- How to extract the most common YEAR from an array of DateTime objects using LINQ