ISqlFromBuilder.FromRaw(string fromClause) 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.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlFromBuilder FromRaw(string fromClause);
Parameters
fromClause
System.String
A string of raw SQL which is a table source (table, view, or derived table).
Actually, you can write any raw SQL if the SQL statement is valid.
Returns
SnapObjects.Data.ISqlFromBuilder
Returns the current ISqlFromBuilder
object.
Examples
The following code example demonstrates how to use the FromRaw(string fromClause) method. It creates a derived table by a subquery 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 Example1()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Defines a SQL statement to create a derived table by a subquery and retrieve all the records from the derived table.
sqlbuilder.Select("*")
.FromRaw("(select name, budget from department) as 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