ISqlModelMapper.TrackDelete<TModel>(TModel model) Method
.NET Standard 2.x
Tracks a database table delete operation. The data that will be deleted from the database table is cached in the TModel
object. When ISqlModelMapper.SaveChanges method is called, a SQL DELETE 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 TrackDelete<TModel>(TModel model);
Type Parameters
TModel
The type of a model class.
Parameters
model
TModel
The TModel
instance that corresponds to the database record.
Returns
SnapObjects.Data.ISqlModelMapper
Returns an ISqlModelMapper
object, which can be used for executing other methods.
Examples
The following code example demonstrates how to delete a student record.
using Appeon.ApiDoc.Models.School;
using System;
namespace Appeon.ApiDoc.ISqlModelMapperExamples
{
public class TrackDeleteExample
{
private SchoolContext _context;
public TrackDeleteExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example1()
{
var mapper = _context.SqlModelMapper;
// Creates a new student.
var newStudent = new Person()
{
LastName = "Senior",
FirstName = "Letitia",
EnrollmentDate = new DateTime(2019, 1, 1),
Discriminator = "Student"
};
// Tracks the new student and saves changes to the database.
var dbResult = mapper.TrackCreate(newStudent)
.SaveChanges();
Console.WriteLine("{0} record has been inserted into the database.",
dbResult.InsertedCount);
// Deletes the student from the database.
dbResult = mapper.TrackDelete(newStudent).SaveChanges();
Console.WriteLine("{0} record has been deleted from the database.",
dbResult.DeletedCount);
/* The code produces the following output:
1 record has been inserted into the database.
1 record has been deleted from the database.
*/
}
}
}
Example Refer To
Model Class: Person
Applies to
.NET Standard
2.x