Simple.Data

Simple.Data defines a number of commands for retrieving data from a data store. These can then be daisychained in a LINQ-like fashion with further methods to modify the basic query. For example, the Distinct method makes sure the returned data contains only distinct values for the named columns.

Distinct

Adds the distinct keyword to the selection of a column.

Syntax

public SimpleQuery Distinct()

Return Value

Type: SimpleQuery
A SimpleQuery object containing a Distinct clause

Remarks

Please read the section on Counting to learn how to use Distinct with Count.

Examples

Distinct with a single column

For example, to return a list of distinct OrderIds from OrderDetails, use the following command.

var albums = db.OrderDetails.All()
               .Select(
                  db.OrderDetails.OrderId.Distinct());

Simple.Data sends the following SQL to the database when albums is evaluated.

select 
   Distinct([dbo].[OrderDetails].[OrderId])
from [dbo].[OrderDetails]

Distinct within a list of columns

For example, to return a list of distinct OrderIds and AlbumIds from OrderDetails, use the following command.

var albums = db.OrderDetails.All()
               .Select(
                  db.OrderDetails.OrderId.Distinct(),
                  db.OrderDetails.AlbumId);

Simple.Data sends the following SQL to the database when albums is evaluated.

select 
   Distinct([dbo].[OrderDetails].[OrderId]),
   [dbo].[OrderDetails].[AlbumId]
from [dbo].[OrderDetails]