ISqlQueryBuilder.Top(int count) Method
.NET Standard 2.x
Adds the TOP
keyword to the SELECT clause of the current object. It specifies that only a certain number of rows will be returned from the result set.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlBuilder Top(int count);
Parameters
count
System.Int32
Specifies the number of rows that will be returned from the result set.
Returns
Returns an ISqlBuilder
object which represents the current object.
Examples
The following code example demonstrates how to use the Top(int count) method to get the first N records from the query result.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlQueryBuilderExamples
{
public class TopExample
{
private SchoolContext _context;
public TopExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Retrieves all records from Department
sqlbuilder.Select("*")
.From("Department", "dept");
// Gets the first record in sqlbuilder.
sqlbuilder.Top(1);
// 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
TOP(1) *
FROM [Department] AS [dept]
*/
}
}
}
Applies to
.NET Standard
2.x