ISqlQueryBuilder.Distinct() Method
.NET Standard 2.x
Adds the DISTINCT
keyword to the SELECT clause of the current object. It specifies that only unique rows can appear in the result set.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlBuilder Distinct();
Returns
Returns an ISqlBuilder
object which represents the current object.
Examples
The following code example demonstrates how to use the Distinct() method to filter the duplicate values from the query result.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlQueryBuilderExamples
{
public class DistinctExample
{
private SchoolContext _context;
public DistinctExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Gets all the values of the "startdate" column from the "Department“ table.
sqlbuilder.Select("startdate")
.From("Department", "dept");
// Filters the duplicate values from the query result.
sqlbuilder.Distinct();
// Converts to raw SQL for the database corresponding to the data context.
string sql = sqlbuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*This code produces the following output:
SELECT
DISTINCT [startdate]
FROM [Department] AS [dept]
*/
}
}
}
Applies to
.NET Standard
2.x