ISqlModelMapper.TrackUpdate<TModel>(TModel model) Method
.NET Standard 2.x
Tracks a database table update operation. The data that will be updated to the database table is cached in the TModel
object. When ISqlModelMapper.SaveChanges method is called, a SQL UPDATE statement will be first generated using the data cached in the TModel
object and the mapping information defined in TModel
class, and then executed.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public ISqlModelMapper TrackUpdate<TModel>(TModel model);
Type Parameters
TModel
The type of a model class.
Parameters
model
TModel
The TModel
object that contains the data you want to update to database.
Returns
SnapObjects.Data.ISqlModelMapper
Returns the current ISqlModelMapper
object, which can be used for executing other methods.
Examples
The following code example demonstrates how to use TrackUpdate<TModel>(TModel)
method to track a database table update operation.
using Appeon.ApiDoc.Models.School;
using System;
namespace Appeon.ApiDoc.ISqlModelMapperExamples
{
public class TrackUpdateExample
{
private SchoolContext _context;
public TrackUpdateExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example1()
{
var mapper = _context.SqlModelMapper;
// Gets the Engineering Department record (DepartmentID = 1) from
// the database.
var department = mapper.LoadByKey<Department>(1).FirstOrDefault();
mapper.TrackUpdate(department);
Console.WriteLine("The department name is {0} (DepartmentID = 1).",
department.Name);
department.Name = "New Name";
mapper.SaveChanges();
// Gets data from the database.
// DepartmentID=1, Name=Engineering_test
department = mapper.LoadByKey<Department>(1).FirstOrDefault();
Console.WriteLine("The name is {0} (DepartmentID = 1).",
department.Name);
/*The code example produces the following output:
The name is Engineering (DepartmentID = 1).
The name is New Name (DepartmentID = 1).
*/
}
}
}
Example Refer To
Model Class: Department
Applies to
.NET Standard
2.x