Show / Hide Table of Contents

    ISqlModelMapper.ClearTracked() Method

    .NET Standard 2.x

    Clears all tracked information.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      public void ClearTracked()
    

    Examples

    The following code example demonstrates how to use the ClearTracked method.

    using Appeon.ApiDoc.Models.School;
    using System;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class ClearTrackedExample
        {
            private SchoolContext _context;
    
            public ClearTrackedExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var mapper = _context.SqlModelMapper;
    
                // Sets the properties for the new student.
                var newStudent = new Person()
                {
                    LastName = "Senior",
                    FirstName = "Letitia",
                    EnrollmentDate = new DateTime(2019, 1, 1),
                    Discriminator = "Student"
                };
    
                // Tracks the new student. This record will be inserted to the database if 
                // the SaveChanges method is called.
                mapper.TrackCreate(newStudent);
    
                // Clears tracked info. No record will be inserted to the database.
                mapper.ClearTracked();
    
                var dbResult = mapper.SaveChanges();
    
                Console.WriteLine("The number of inserted row(s) is {0}.",
                    dbResult.InsertedCount);
    
                /* The code produces the following output:
                
                The number of inserted row(s) is 0.
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Person

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon