ISqlModelMapper Interface
.NET Standard 2.x |  Current Version (1.0.1) 
When SqlModelMapper is used to save data, it can automatically commit all tracked data operations in one transaction to achieve data integrity.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
 public interface ISqlModelMapper;
Methods
| Name | Return Type | Description | 
|---|---|---|
| Avg<TModel>(string expression,params object[] parameters) | object | Computes the average value using the specified SQL expression for the data retrieved according to the criteria specified in a TModelclass. | 
| ClearTracked() | void | Clears all tracked information. | 
| Count<TModel>(params object[] parameters) | int | Gets the number of rows in the result set retrieved according to the criteria specified in a TModelclass. | 
| DistinctCount<TModel>(string expression,params object[] parameters) | int | Gets the number of all distinct values specified by the SQL expression, according to the criteria specified in a TModelclass. | 
| Exists<TModel>(params object[] parameters) | bool | Checks whether any record exists according to the retrieval criteria specified in a TModelclass. | 
| KeyExists<TModel>(params object[] parameters) | bool | Checks whether data exists when retrieved, according to the primary key defined in a TModelclass. | 
| Load<TModel>(params object[] parameters) | ILoadable<TModel> | Retrieves data according to the SQL query defined in a TModelclass. | 
| Load<TModel>(ISqlQueryBuilder queryBuilder, params object[] parameters) | ILoadable<TModel> | Retrieves data according to the SQL query defined in an ISqlQueryBuilderobject. | 
| LoadAll<TModel>() | ILoadable<TModel> | Retrieves data from the database according to the SQL query (without the Where clause) defined by the primary table in a TModelclass. | 
| LoadAllByPage<TModel>(int currentIndex, int pageSize) | ILoadable<TModel> | Retrieves data for the specified page according to the SQL query (without the Where clause) defined by the primary table in a TModelclass. | 
| LoadByKey<TModel>(params object[] parameters) | ILoadable<TModel> | Retrieves data according to the primary key defined in a TModelclass. | 
| LoadByPage<TModel>(int currentIndex, int pageSize, params object[] parameters) | ILoadable<TModel> | Retrieves data for the specified page according to the SQL query defined in a TModelclass. | 
| LoadEmbedded<TModel>(TModel model, params object[] parameters) | IEmbeddedLoadable<TModel> | Obtains an IEmbeddedLoadable<TModel>object, which can be used to load the embedded property of aTModelinstance. | 
| Max<TModel>(string expression, params object[] parameters) | object | Gets the maximum value for the specified SQL expression, according to the retrieval criteria specified in a TModelclass. | 
| Min<TModel>(string expression, params object[] parameters) | object | Gets the minimum value for the specified SQL expression, according to the retrieval criteria specified in a TModelclass. | 
| RemoveTrackedModel<TModel>(TModel model) | bool | Clears all tracked information from a model. | 
| SaveChanges() | IDbResult | Saves all of the data changes to the database, by executing the database table operations tracked by the ISqlModelMapperobject, and calls the trackedActiondelegates during operations. | 
| Scalar<TModel, TValue>(string expression, params object[] parameters) | TValue | Retrieves data from the first column, in the first row, for the specified SQL expression, according to the criteria specified in a TModelclass. | 
| ScalarByKey<TModel, TValue>(string expression, params object[] parameters) | TValue | Retrieves data from the first column, in the first row, for the specified SQL expression according to the primary key in a TModelclass. | 
| Sum | object | Computes the sum of the value using the specified SQL expression for the data retrieved according to the criteria specified in a TModelclass. | 
| Track(Action<ISaveContext> saveAction) | ISqlModelMapper | Tracks an Action<ISaveContext>object. | 
| Track<TModel>(IModelEntry<TModel> modelEntry) | TModel | Tracks a database table operation (insert, update, or delete). The data state determines which type of operation (insert, update, or delete) to be performed. The data to be manipulated is cached in the TModelobject. | 
| Track<TModel>(IModelEntry<TModel> modelEntry, Action<ISaveContext> afterSaveAction) | TModel | Tracks a database table operation (insert, update, or delete) and an Action<ISaveContext>object. The data state determines which type of operation (insert, update, or delete) to be performed. The data to be manipulated is cached in theTModelobject. | 
| TrackCreate<TModel>(TModel model) | ISqlModelMapper | Tracks a database table insert operation. The data that will be inserted into the database table is cached in the TModelobject. | 
| TrackCreate<TModel>(TModel model, Action<ISaveContext> afterSaveAction) | ISqlModelMapper | Tracks a database table insert operation and an Action<ISaveContext>object. The data that will be inserted into the database table is cached in theTModelobject. | 
| TrackCreateRange<TModel>(IEnumerable<TModel> models) | ISqlModelMapper | Tracks one or more database table insert operations. The data that will be inserted into the database table is cached in the TModelobject. | 
| TrackDelete<TModel>(TModel model) | ISqlModelMapper | Tracks a database table delete operation. The data that will be deleted from the database table is cached in the TModelobject. | 
| TrackDelete<TModel>(TModel model, Action<ISaveContext> afterSaveAction) | ISqlModelMapper | Tracks a database table delete operation and an Action<ISaveContext>object. The data that will be deleted from the database table is cached in theTModelobject. | 
| TrackDeleteByKey<TModel>(params object[] parameters) | ISqlModelMapper | Tracks a database table delete operation by the primary key. A SQL DELETE statement will be generated using the primary key value(s) and the mapping information defined in TModel. | 
| TrackDeleteRange<TModel>(IEnumerable<TModel> models) | ISqlModelMapper | Tracks one or more database table delete operations. The data that will be deleted from the database table is cached in the TModelobject. | 
| TrackMaster<TModel>(IModelEntry<TModel> modelEntry) | IDetailTracker<TModel> | Tracks an insert, update or delete operation to the master table, when working with multiple models which are in the master-detail relationship. The data state determines which type of operation (insert, update or delete) will be performed. The data to be manipulated is cached in the TModelobject. | 
| TrackMaster<TModel>(IModelEntry<TModel> modelEntry, Action<ISaveContext> afterSaveAction) | IDetailTracker<TModel> | Tracks an insert, update or delete operation to the master table and an Action<ISaveContext>object, when working with multiple models which are in the master-detail relationship. The data state determines which type of operation (insert, update or delete) will be performed. The data to be manipulated is cached in theTModelobject. | 
| TrackRange<TModel>(IEnumerable<IModelEntry<TModel>> modelEntries) | IList<TModel> | 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 TModelobjects. | 
| TrackSqlBuilder(ISqlInsertBuilder insertBuilder, params object[] parameters) | ISqlModelMapper | Tracks a database table insert operation. A SQL INSERT statement will be generated using the specified ISqlInsertBuilderobject. | 
| TrackSqlBuilder(ISqlDeleteBuilder deleteBuilder, params object[] parameters) | ISqlModelMapper | Tracks a database table delete operation. A SQL DELETE statement will be generated using the specified ISqlDeleteBuilderobject. | 
| TrackSqlBuilder<TModel>(ISqlUpdateBuilder updateBuilder, params object[] parameters) | ISqlModelMapper | Tracks a database table update operation. A SQL UPDATE statement will be generated using the specified ISqlUpdateBuilderobject. | 
| TrackSqlCUD(string sqlText, params object[] parameters) | ISqlModelMapper | Tracks a database table operation (insert, update or delete) using a raw SQL statement (INSERT, UPDATE, or DELETE). | 
| TrackUpdate<TModel>(TModel model) | ISqlModelMapper | Tracks a database table update operation. The data that will be updated to the database table is cached in the TModelobject. | 
| TrackUpdate<TModel>(TModel model, Action<ISaveContext> afterSaveAction) | ISqlModelMapper | Tracks a database table update operation and an Action<ISaveContext>object. The data that will be updated to the database table is cached in theTModelobject. | 
| TrackUpdate<TModel>(TModel originalModel, TModel modifiedModel) | ISqlModelMapper | Tracks a database table update operation. The data that will be updated to the database table is cached in the modifiedModeland the original data is cached in theoriginalModel. | 
| TrackUpdate<TModel>(TModel originalModel, TModel modifiedModel, Action<ISaveContext> afterSaveAction) | ISqlModelMapper | Tracks a database table update operation and an Action<ISaveContext>object. The data that will be updated to the database table is cached in themodifiedModeland the original data is cached in theoriginalModel. | 
| TrackUpdateRange<TModel>(IEnumerable<TModel> models) | ISqlModelMapper | Tracks one or more database table update operations. The data that will be updated to the database table is cached in the TModelobjects. | 
| ValidateTrackedModels() | bool | Performs validity check to all data in the model tracked by the current ISqlModelMapperobject. | 
| ValidateTrackedModels(out List<ValidationResult> ValidationResults) | bool | Performs validity check to all  data in the model  tracked by the current ISqlModelMapperobject and gets the validation result. | 
Remarks
SqlModelMapper is an easy-to-use data manipulation component. It maps the database table to the C# objects and provides flexible interfaces for manipulating the database. Developer can easily manage the object relationships and cascading operations with simple coding, and perform various operations to the database via writing almost no SQL statements.
Tracking
SqlModelMapper provides various track methods. The track method keeps track of the database operation only, but does not execute the operations. When multiple track methods are called, the order of the tracks determines the order of the database operations to be executed. When the IModeMapper.SaveChanges method is called to actually execute the database operations, all of these operations will be executed in the same transaction. When a succeeding operation relies on the execution result of a proceeding operation, the developer can use the Action<ISaveAction> parameter of the ISqlModelMapper.Track method to receive and pass along the context when the data is saved. After the IModeMapper.SaveChanges method executes the database operations, all of the tracked operations will be restored to the initial state.