ISqlQueryBuilder.Select(ISqlBuilder sqlBuilder) Method
.NET Standard 2.x
Adds a column (which is returned by a subquery specified by an ISqlBuilder
object) to the select list of a SELECT clause. It uses the name
property of the ISqlBuilder
object as the alias for this column by default.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlQueryBuilder Select(ISqlBuilder sqlBuilder);
Parameters
sqlBuilder
SnapObjects.Data.ISqlBuilder
An ISqlBuilder
object which represents a SQL subquery.
Returns
SnapObjects.Data.ISqlQueryBuilder
Returns the current ISqlQueryBuilder
object.
Examples
The following code example demonstrates how to use the Select(ISqlBuilder sqlBuilder) method. The column is selected using a subquery.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlQueryBuilderExamples
{
public class SelectExample
{
private SchoolContext _context;
public SelectExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example1()
{
// Declares SqlQueryBuilder.
var subsqlbuilder = new SqlQueryBuilder();
var sqlbuilder = new SqlQueryBuilder();
// Defines a subquery SQL statement and associates the Department table with the Course table
// using the WHERE condition: Department.departmentid = course.departmentid.
subsqlbuilder.Select("name")
.From("Department")
.Where("departmentid", "c.departmentid");
// Defines a SQL statement to retrieve Title values from the "Course" table,
// and Name values from the "Department" table.
sqlbuilder.Select("title")
.Select(subsqlbuilder)
.From("course", "c");
// 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
[title],
(SELECT
[name]
FROM [Department]
WHERE ([departmentid] = [c].[departmentid]))
FROM [course] AS [c]
*/
}
}
}
Applies to
.NET Standard
2.x