Show / Hide Table of Contents

    ISqlModelMapper.TrackUpdateRange<TModel>(IEnumerable<TModel> models) Method

    .NET Standard 2.x

    Tracks one or more database table update operations. The data that will be updated to the database table is cached in the TModel objects. When ISqlModelMapper.SaveChanges method is called, one or more SQL UPDATE statements will be first 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 ISqlModelMapper TrackUpdateRange<TModel>(IEnumerable<TModel> models);
    

    Type Parameters

    TModel

    The type of a model class.

    Parameters

    models System.Collections.Generic.IEnumerable<TModel>

    A sequence of TModel objects used for updating one or multiple records in 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 track one or more database table update operations.

    using Appeon.ApiDoc.Models.School;
    using System;
    using System.Collections.Generic;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class TrackUpdateRangeExample
        {
            private SchoolContext _context;
    
            public TrackUpdateRangeExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
    
                var mapper = _context.SqlModelMapper;
                var models = new List<Department>();
    
                // Gets the Engineering Department record (DepartmentID = 1) from 
                // the database.
                var department = mapper.LoadByKey<Department>(1).FirstOrDefault();
    
                // Gets the English Department record (DepartmentID = 2) 
                // from the database.
                var department2 = mapper.LoadByKey<Department>(2).FirstOrDefault();
    
                models.Add(department);
                models.Add(department2);
    
                mapper.TrackUpdateRange(models);
    
                Console.WriteLine("The name is {0} (DepartmentID = 1).",
                   department.Name);
                Console.WriteLine("The name is {0} (DepartmentID = 2).",
                   department2.Name);
    
                department.Name = "Engineering New";
                department2.Name = "English New";
    
                mapper.SaveChanges();
    
                // Gets data from the database.
                // DepartmentID=1, Name=Engineering New
                // DepartmentID=2, Name=English New
                department = mapper.LoadByKey<Department>(1).FirstOrDefault();
                department2 = mapper.LoadByKey<Department>(2).FirstOrDefault();
                Console.WriteLine();
                Console.WriteLine("The name is {0} (DepartmentID = 1).",
                    department.Name);
                Console.WriteLine("The name is {0} (DepartmentID = 2).",
                   department2.Name);
    
                /*The code example produces the following output:
                
                The name is Engineering (DepartmentID = 1).
                The name is English (DepartmentID = 2).
    
                The name is Engineering New (DepartmentID = 1).
                The name is English New (DepartmentID = 2).
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon