SqlExecutor.SqlExecutor() Constructor
.NET Standard 2.x | Current Version (1.0.1)
Initializes a new instance of the SqlExecutor class.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public SqlExecutor(DataContext context);
parameters
context
A DataContext object which contains the database connection information.
Examples
The following code example initializes a SqlExecutor object.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.SqlExecutorExamples
{
public class SqlExecutorExample
{
private readonly SchoolContext _context;
public SqlExecutorExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
// Creates a SqlExecutor object.
var executor1 = new SqlExecutor(_context);
// You can also creates a SqlExecutor object by the
// DataContext.SqlExecutor property.
var executor2 = _context.SqlExecutor;
// Defines SQL statement.
var sql = "update Course set Title = 'New Title'" +
" where CourseID = 8001";
// Executes the SQL statement and returns the number of affected rows.
var rowAffected = executor2.Execute(sql);
Console.WriteLine("{0} record has been updated into the database.",
rowAffected);
/*This code produces the following output:
1 records have been updated into the database.
*/
}
}
}
Applies to
.NET Standard
2.x