namespace SharedDATA.Api { using System; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; /// /// Defines the interface(s) for unit of work. /// public interface IUnitOfWork : IDisposable { /// /// Changes the database name. This require the databases in the same machine. NOTE: This only work for MySQL right now. /// /// The database name. /// /// This only been used for supporting multiple databases in the same model. This require the databases in the same machine. /// void ChangeDatabase(string database); /// /// Gets the specified repository for the . /// /// True if providing custom repositry /// The type of the entity. /// An instance of type inherited from interface. IRepository GetRepository(bool hasCustomRepository = false) where TEntity : class; /// /// Gets the db context. /// /// TContext GetDbContext() where TContext : DbContext; /// /// Saves all changes made in this context to the database. /// /// True if sayve changes ensure auto record the change history. /// The number of state entries written to the database. int SaveChanges(bool ensureAutoHistory = false); /// /// Asynchronously saves all changes made in this unit of work to the database. /// /// True if save changes ensure auto record the change history. /// A that represents the asynchronous save operation. The task result contains the number of state entities written to database. Task SaveChangesAsync(bool ensureAutoHistory = false); /// /// Executes the specified raw SQL command. /// /// The raw SQL. /// The parameters. /// The number of state entities written to database. int ExecuteSqlCommand(string sql, params object[] parameters); /// /// Uses raw SQL queries to fetch the specified data. /// /// The type of the entity. /// The raw SQL. /// The parameters. /// An that contains elements that satisfy the condition specified by raw SQL. IQueryable FromSql(string sql, params object[] parameters) where TEntity : class; /// /// Uses TrakGrap Api to attach disconnected entities /// /// Root entity /// Delegate to convert Object's State properities to Entities entry state. void TrackGraph(object rootEntity, Action callback); } }