ISqlFromBuilder.FromRaw(string fromClause, string builderAlias) Method
.NET Standard 2.x
Adds a table source (table, view, or derived table), specified by a raw SQL, to the FROM clause of the current object, and specifies an alias for this table source.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlFromBuilder FromRaw(string fromClause, string builderAlias);
Parameters
fromClause
System.String
A string of raw SQL which is the table source (table, view, or derived table).
Actually, you can write any raw SQL if the SQL statement is valid.
builderAlias
System.String
The alias for the table source.
Returns
SnapObjects.Data.ISqlFromBuilder
Returns the current ISqlFromBuilder
object.
Examples
The following code example demonstrates how to use the FromRaw(string fromClause, string builderAlias) method. It creates a derived table by a subquery with the alias "dept" and retrieves all the records from the derived table.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlFromBuilderExamples
{
public class FromRawExample
{
private SchoolContext _context;
public FromRawExample(SchoolContext dataContext)
{
// Sets the Data Context
_context = dataContext;
}
public void Example2()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Defines a SQL statement to create a derived table by a subquery with the alias "dept",
// and retrieve all the records from the derived table.
sqlbuilder.Select("*")
.FromRaw("(select name, budget from department) as dept", "Dept");
// 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
*
FROM (SELECT
[name],
[budget]
FROM [department]) AS [dept]
*/
}
}
}
Applies to
.NET Standard
2.x