Telerik OpenAccess ORM

Telerik OpenAccess ORM Send comments on this topic.
How to: Remove Duplicate Elements
See Also
Programmer's Guide > Feature Reference > API > LINQ Guide > How to: Remove Duplicate Elements

Glossary Item Box

This topic provides an example of how to remove duplicate elements from query results by using Distinct. The example uses the Distinct method to return the unique country names.

To run the code in this example, you need to create a new Telerik OpenAccess Domain Model based on the Northwind database.

The following code is the LINQ example.

C# Copy Code
using ( EntitiesModel dbContext = new EntitiesModel() )
{
   IQueryable<
string> countries = from customer in dbContext.Customers
                                  select customer.Country;
   IQueryable<
string> distinctCountries = countries.Distinct();
   
foreach ( string country in distinctCountries )
   {
       Console.WriteLine( country );                    
   }
}
VB.NET Copy Code
Using dbContext As New EntitiesModel()
 Dim countries As IQueryable(Of String) = From customer In dbContext.Customers
                                          Select customer.Country
 Dim distinctCountries As IQueryable(Of String) = countries.Distinct()
 For Each country As String In distinctCountries
  Console.WriteLine(country)
 Next country
End Using

See Also