Show / Hide Table of Contents

    IDetailTracker.TrackGrandDetails<TDetailModel, TGrandDetailModel>(Expression<Func<TModel, object>> propertyExpr, Expression<Func<TDetailModel, object>> detailPropertyExpr, IEnumerable<IModelEntry<TGrandDetailModel>> grandModelEntries) Method

    .NET Standard 2.x

    Tracks an insert, update or delete operation on the table which the granddetail model is mapped to when working with the master-detail-granddetail models where the ModelEmbedded attribute is applied in a property of the master model and a property of the detail model. The data state determines which type of operation to be performed. The data to be manipulated is cached in a sequence of TGrandDetailModel objects.

    When ISqlModelMapper.SaveChanges is called, a SQL statement (INSERT, UPDATE, or DELETE) will be generated using the data cached in TGrandDetailModel and the mapping information defined in TGrandDetailModel, and then the SQL statement will be executed.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    	IDetailTracker<TModel> TrackGrandDetails<TDetailModel, TGrandDetailModel>(Expression<Func<TModel, object>> propertyExpr, Expression<Func<TDetailModel, object>> detailPropertyExpr, IEnumerable<IModelEntry<TGrandDetailModel>> grandModelEntries);
    
    

    Type Parameters

    TDetailModel

    The type of the detail model class.

    TGrandDetailModel

    The type of the granddetail model class.

    Parameters

    propertyExpr System.Linq.Expressions.Expression<Func<TModel, object>>

    A property of the master model where the ModelEmbedded attribute is applied.

    The type of this property is TDetailModel.

    This property is specified by an expression.

    detailPropertyExpr System.Linq.Expressions.Expression<Func<TDetailModel, object>>

    A property of the detail model where the ModelEmbedded attribute is applied.

    The type of this property is a collection of TGrandDetailModel.

    This property is specified by an expression.

    grandModelEntry System.Collections.Generic.IEnumerable<SnapObjects.Data.IModelEntry<TGrandDetailModel>>

    An IEnumerable<IModelEntry<TGrandDetailModel>> object which contains the data and data state and which will be tracked. The data corresponds to the second property expression.

    Returns

    SnapObjects.Data.IDetailTracker<TModel>

    Returns the current IDetailTracker<TModel> object.

    Remarks

    The ModelEmbedded attribute must be applied in TModel and TDetailModel to create the master-detail-granddetail relationship between TModel, TDetailModel and TGrandDetailModel.

    The ISqlModelMapper.TrackMaster method can track the master model and return the IDetailTracker<TModel> object. The IDetailTracker.TrackDetail method can be used to track the detail model. Then the IDetailTracker.TrackGrandDetails method can be used to track the granddetail model object.

    One-to-one-to-many

    The type of the property specified by the propertyExpr parameter is TDetailModel (which represents one row in the detail database table). The type of the property specified by the detailPropertyExpr parameter is a collection of TGrandDetailModel (which represents multiple rows in the granddetail database table). Therefore, the IDetailTracker.TrackGrandDetails method applies to the one-to-one-to-many table relationship (one master table record to one detail table record to many granddetail table records).

    Examples

    The following code example demonstrates how to save the master table, the detail table, and the grand-detail table synchronously; the master table and the detail table have only one affected record and the grand-detail table has two affected records.

    using SnapObjects.Data;
    using Appeon.ApiDoc.Models.School;
    using System;
    using System.Collections.Generic;
    
    namespace Appeon.ApiDoc.IDetailTrackerExamples
    {
        public class TrackGrandDetailsExample
        {
            private readonly SchoolContext _context;
    
            public TrackGrandDetailsExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example(IModelEntry<DepartmentInfo> depart,
                IModelEntry<CourseInfo> course,
                IEnumerable<IModelEntry<CourseStudentInfo>> courseStudents)
            {
                // Saves the master table, the detail table, and the grand-detail table.     
                var mapper = _context.SqlModelMapper;
    
                var master = mapper.TrackMaster(depart)
                           .TrackDetail(m => m.Courses, course)
                           .TrackGrandDetails<CourseInfo, CourseStudentInfo>(
                                m => m.Courses,
                                d => d.Students,
                                courseStudents)
                           .MasterModel;
    
                var dbResult = mapper.SaveChanges();
    
                // Shows the saving result.
                Console.WriteLine("{0} records have been inserted into the database.",
                    dbResult.AffectedCount);
    
                /* This code example produces the following output:
                
                4 records have been inserted into the database.
                */
            }
        }
    }
    

    Example Refer To

    Model Classes: CourseInfo CourseStudentInfo DepartmentInfo

    Applies to

    .NET Standard

    2.x

    See Also

    IDetailTracker.TrackDetail

    ISqlModelMapper.TrackMaster

    Back to top Generated by Appeon