Show / Hide Table of Contents

    ISqlModelMapper.TrackRange<TModel>(IEnumerable<IModelEntry<TModel>> modelEntries) Method

    .NET Standard 2.x

    Tracks one or more database table operations (insert, update or delete). The data state determines which type of operation will be performed. The data to be manipulated is cached in the TModel objects. When ISqlModelMapper.SaveChanges method is called, one or more SQL statements (INSERT, UPDATE or DELETE) will be generated using the data cached in the TModel objects and the mapping information defined in TModel class, and then executed.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      public IList<TModel> TrackRange<TModel>(IEnumerable<IModelEntry<TModel>> modelEntries);
    

    Type Parameters

    TModel

    The type of a model class.

    Parameters

    modelEntries System.Collections.Generic.IEnumerable<SnapObjects.Data.IModelEntry<TModel>>

    A sequence of IModelEntry<TModel> objects containing data and state.

    Returns

    System.Collections.Generic.IList<TModel>

    A list of TModel objects which have been tracked by this method.

    Remarks

    If you need to continue to modify the tracked data after calling this method, please do not modify the modelEntries object, but modify the model objects returned by this method.

    Examples

    The following code example demonstrates how to create two records of students.

    using SnapObjects.Data;
    using Appeon.ApiDoc.Models.School;
    using System;
    using System.Collections.Generic;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class TrackRangeExample
        {
            private SchoolContext _context;
    
            public TrackRangeExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example(IEnumerable<IModelEntry<Person>> newStudents)
            {
                var mapper = _context.SqlModelMapper;
    
                // Tracks the Insert operation for the new students.
                mapper.TrackRange(newStudents);
    
                // Saves to the database.
                var dbResult = mapper.SaveChanges();
    
                Console.WriteLine("{0} student records have been inserted into the " +
                                    "database.",
                                    dbResult.InsertedCount);
    
                /* The code produces the following output:
                
                1 student record has been inserted into the database.
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Person

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon