Show / Hide Table of Contents

    ISqlModelMapper.RemoveTrackedModel<TModel>(TModel model) Method

    .NET Standard 2.x

    Clears all tracked information from a model.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      public bool RemoveTrackedModel<TModel>(TModel model)
    

    Type Parameters

    TModel

    The type of a model class.

    Parameters

    model TModel

    The model object whose tracked information you want to remove.

    Returns

    System.Boolean

    Returns true if the tracked information of the model object has been removed; returns false if tracked information of the model does not exist or the model is null.

    Examples

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

    using Appeon.ApiDoc.Models.School;
    using System;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class RemoveTrackedModelExample
        {
            private SchoolContext _context;
    
            public RemoveTrackedModelExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var mapper = _context.SqlModelMapper;
    
                // Sets the properties of the new students.
                var newStudentA = new Person()
                {
                    LastName = "Ruskin",
                    FirstName = "Lionel",
                    EnrollmentDate = new DateTime(2019, 1, 1),
                    Discriminator = "Student"
                };
    
                var newStudentB = new Person()
                {
                    LastName = "Effie",
                    FirstName = "Lilith",
                    EnrollmentDate = new DateTime(2019, 1, 1),
                    Discriminator = "Student"
                };
    
                // Tracks the new student A
                mapper.TrackCreate(newStudentA);
    
                // Tracks the new student B
                mapper.TrackCreate(newStudentB);
    
                // Removes the tracked info of student A.
                // Only student B will be inserted to the database.
                mapper.RemoveTrackedModel(newStudentA);
    
                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 1.
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Person

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon