ISqlQueryBuilder.Select(ISqlBuilder sqlBuilder, string alias) 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 and specifies an alias for this column.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlQueryBuilder Select(ISqlBuilder sqlBuilder, string alias);
Parameters
sqlBuilder
SnapObjects.Data.ISqlBuilder
An ISqlBuilder
object which represents a SQL subquery.
alias
System.String
The alias for this column.
Returns
SnapObjects.Data.ISqlQueryBuilder
Returns the current ISqlQueryBuilder
object.
Examples
The following code example demonstrates how to use the Select(ISqlBuilder sqlBuilder, string alias) method. The column is selected using a subquery and is given an alias.
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 Example2()
{
// 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.
// Specifies "name" as the alias of the name column selected by the subquery.
sqlbuilder.Select("title")
.Select(subsqlbuilder, "name")
.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])) AS [name]
FROM [course] AS [c]
*/
}
}
}
Applies to
.NET Standard
2.x