ISqlBuilderBase.ToSqlString(DataContext context) Method
.NET Standard 2.x
Returns the raw SQL string for the corresponding database by the current object.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
string ToSqlString(DataContext context);
Parameters
context
SnapObjects.Data.DataContext
A DataContext
object which contains the database connection information.
Returns
System.String
Returns the raw SQL string.
Examples
The following code example demonstrates how to get the SQL statement generated for the specified database.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlBuilderBaseExamples
{
public class ToSqlStringExample
{
private SchoolContext _context;
public ToSqlStringExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example()
{
// Builds a SQL statement.
var sqlBuilder = new SqlQueryBuilder();
sqlBuilder.Select("name")
.From("Department")
.WhereValue("DepartmentId", 1);
// Gets the SQL statement generated for the specified database.
bool valid = sqlBuilder.Validate(_context);
Console.WriteLine("The SQL statement: \n{0}",
sqlBuilder.ToSqlString(_context));
/*This code produces the following output:
The SQL statement:
SELECT
[name]
FROM [Department]
WHERE ([DepartmentId] = 1)
*/
}
}
}
Applies to
.NET Standard
2.x