ISqlModelMapper Interface
.NET Standard 2.x
SqlModelMapper is a transaction-oriented data manipulation component compliant with .NET Standard. It can build models with data from multiple tables, support nested levels of relationships, and provide explicit and implicit transaction management for business entities (i.e. a top-level object and all of its children).
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 TModel class. |
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 TModel class. |
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 TModel class. |
Exists<TModel>(params object[] parameters) | bool | Checks whether any record exists according to the retrieval criteria specified in a TModel class. |
GetQueryBuilder<TModel>(bool removeWhereClause = false) | IQueryBuilder<TModel> | Gets the query conditions of a dynamic query. |
KeyExists<TModel>(params object[] parameters) | bool | Checks whether data exists when retrieved, according to the primary key defined in a TModel class. |
Load<TModel>(params object[] parameters) | ILoadable<TModel> | Retrieves data according to the SQL query defined in a TModel class. |
LoadAsync<TModel>(params object[] parameters) | Task<ILoadable<TModel>> | Asynchronously retrieves data according to the SQL query defined in a TModel class. |
LoadAsync<TModel>(object[] parameters, CancellationToken cancellationToken) | Task<ILoadable<TModel>> | Asynchronously retrieves data according to the SQL query defined in a TModel class. |
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 TModel class. |
LoadAllAsync<TModel>() | Task<ILoadable<TModel>> | Asynchronously retrieves data from the database according to the SQL query (without the Where clause) defined by the primary table in a TModel class. |
LoadAllAsync<TModel>(CancellationToken cancellationToken) | Task<ILoadable<TModel>> | Asynchronously retrieves data from the database according to the SQL query (without the Where clause) defined by the primary table in a TModel class. |
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 TModel class. |
LoadAllByPageAsync<TModel>(int currentIndex, int pageSize) | Task<ILoadable<TModel>> | Asynchronously retrieves data starting from a specified row according to the SQL query (without the Where clause) defined by the primary table in a TModel class. |
LoadAllByPageAsync<TModel>(int currentIndex, int pageSize, CancellationToken cancellationToken) | Task<ILoadable<TModel>> | Asynchronously retrieves data starting from a specified row according to the SQL query (without the Where clause) defined by the primary table in a TModel class. |
LoadByKey<TModel>(params object[] parameters) | ILoadable<TModel> | Retrieves data according to the primary key defined in a TModel class. |
LoadByKeyAsync<TModel>(params object[] parameters) | Task<ILoadable<TModel>> | Asynchronously retrieves data according to the primary key defined in a TModel class. |
LoadByKeyAsync<TModel>(object[] parameters, CancellationToken cancellationToken) | Task<ILoadable<TModel>> | Asynchronously retrieves data according to the primary key defined in a TModel class. |
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 TModel class. |
LoadByPageAsync<TModel>(int currentIndex, int pageSize, params object[] parameters) | Task<ILoadable<TModel>> | Asynchronously retrieves data starting from a specified row according to the SQL query defined in a TModel class. |
LoadByPageAsync<TModel>(int currentIndex, int pageSize, object[] parameters, CancellationToken cancellationToken) | Task<ILoadable<TModel>> | Asynchronously retrieves data starting from a specified row according to the SQL query defined in a TModel class. |
LoadEmbedded<TModel>(TModel model, params object[] parameters) | IEmbeddedLoadable<TModel> | Obtains an IEmbeddedLoadable<TModel> object, which can be used to load the embedded property of a TModel instance. |
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 TModel class. |
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 TModel class. |
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 ISqlModelMapper object, and calls the tracked Action delegates during operations. |
SaveChangesAsync() | Task<IDbResult> | Asynchronously saves all of the data changes to the database, by executing the database table operations tracked by the ISqlModelMapper object, and calls the tracked Action delegates during operations. |
SaveChangesAsync(CancellationToken cancellationToken) | Task<IDbResult> | Asynchronously saves all of the data changes to the database, by executing the database table operations tracked by the ISqlModelMapper object, and calls the tracked Action delegates 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 TModel class. |
ScalarAsync<TModel, TValue>(string expression, params object[] parameters) | Task<TValue> | Asynchronously retrieves data from the first column, in the first row, for the specified SQL expression, according to the criteria specified in a TModel class. |
ScalarAsync<TModel, TValue>(string expression, object[] parameters, CancellationToken cancellationToken) | Task<TValue> | Asynchronously retrieves data from the first column, in the first row, for the specified SQL expression, according to the criteria specified in a TModel class. |
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 TModel class. |
ScalarByKeyAsync<TModel, TValue>(string expression, params object[] parameters) | Task<TValue> | Asynchronously retrieves data from the first column, in the first row, for the specified SQL expression according to the primary key in a TModel class. |
ScalarByKeyAsync<TModel, TValue>(string expression, object[] parameters, CancellationToken cancellationToken) | Task<TValue> | Asynchronously retrieves data from the first column, in the first row, for the specified SQL expression according to the primary key in a TModel class. |
Sum | object | Computes the sum of the value using the specified SQL expression for the data retrieved according to the criteria specified in a TModel class. |
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 TModel object. |
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 the TModel object. |
Track(IMapperTrackable mapperTrackable, params object[] saveParms) | ISqlModelMapper | Tracks an IMapperTrackable object. When ISqlModelMapper.SaveChanges method is called, the SaveChanges method of this object will be called. |
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 TModel object. |
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 the TModel object. |
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 TModel object. |
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 TModel object. |
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 the TModel object. |
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 TModel object. |
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 TModel object. |
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 the TModel object. |
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 TModel objects. |
TrackSqlBuilder(ISqlInsertBuilder insertBuilder, params object[] parameters) | ISqlModelMapper | Tracks a database table insert operation. A SQL INSERT statement will be generated using the specified ISqlInsertBuilder object. |
TrackSqlBuilder(ISqlDeleteBuilder deleteBuilder, params object[] parameters) | ISqlModelMapper | Tracks a database table delete operation. A SQL DELETE statement will be generated using the specified ISqlDeleteBuilder object. |
TrackSqlBuilder<TModel>(ISqlUpdateBuilder updateBuilder, params object[] parameters) | ISqlModelMapper | Tracks a database table update operation. A SQL UPDATE statement will be generated using the specified ISqlUpdateBuilder object. |
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 TModel object. |
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 the TModel object. |
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 modifiedModel and the original data is cached in the originalModel . |
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 the modifiedModel and the original data is cached in the originalModel . |
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 TModel objects. |
ValidateTrackedModels() | bool | Performs validity check to all data in the model tracked by the current ISqlModelMapper object. |
ValidateTrackedModels(out List<ValidationResult> ValidationResults) | bool | Performs validity check to all data in the model tracked by the current ISqlModelMapper object 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.