ISqlModelMapper.TrackSqlBuilder(ISqlUpdateBuilder updateBuilder, params object[] parameters) Method
.NET Standard 2.x
Tracks a database table update operation. A SQL UPDATE statement will be generated using the specified ISqlUpdateBuilder object. When ISqlModelMapper.SaveChanges method is called, the SQL UPDATE statement will be executed.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public ISqlModelMapper TrackSqlBuilder(ISqlUpdateBuilder updateBuilder, params object[] parameters);
Parameters
updateBuilder SnapObjects.Data.ISqlUpdateBuilder
An ISqlUpdateBuilder object used to build the SQL UPDATE statement.
parameters System.Object[]
One or more values that you want to use as arguments in the SQL UPDATE statement defined in updateBuilder.
Returns
SnapObjects.Data.ISqlModelMapper
Returns an ISqlModelMapper object, which can be used for executing other methods.
Examples
The following code example demonstrates how to modify a student.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlModelMapperExamples
{
public class TrackSqlBuilderExample
{
private SchoolContext _context;
public TrackSqlBuilderExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example3()
{
var updateBuilder = new SqlUpdateBuilder();
// Builds a SQL Update statement with no parameters to update the
// enrollment date for a student.
updateBuilder.Update("Person")
.SetValue("EnrollmentDate", new DateTime(2019, 1, 2))
.From("Person")
.Where("LastName", "'Senior'")
.AndWhere("FirstName", "'Letitia'");
Console.WriteLine("SQL Update Statement is:");
Console.WriteLine(updateBuilder.ToSqlString(_context));
// Tracks the SQL Update statement and executes it in the database.
var dbResult = _context.SqlModelMapper.TrackSqlBuilder(updateBuilder)
.SaveChanges();
/* The code produces the following output:
UPDATE [Person] SET [EnrollmentDate] = '2019-01-02 00:00:00.000'
FROM [Person]
WHERE ([LastName] = 'Senior'
AND [FirstName] = 'Letitia')
*/
}
}
}
Applies to
.NET Standard
2.x