//代碼調用由業務層調用,調用方式詳見源代碼的業務層,升級直接替換TT模板便可,無需覆蓋系統
using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Apps.IDAL
{
public interface IBaseRepository<T> : IDisposable
{
#region 建立記錄(異步與同步方法)
bool Create(T model, bool isCommit = true);
Task<bool> CreateAsync(T model, bool isCommit = true);
bool CreateList<T1>(List<T1> T, bool IsCommit = true) where T1 : class;
Task<bool> CreateListAsync<T1>(List<T1> T, bool IsCommit = true) where T1 : class;
#endregion
#region 修改記錄 (異步和同步方法)
bool Edit(T model, bool isCommit = true);
Task<bool> EditAsync(T model, bool isCommit = true);
/// <summary>
/// 批量
/// </summary>
/// <param name="whereLambda">表達式</param>
/// <param name="updateLambda">m_Rep.BatchUpdate(a=>a.Age==36,a=>new SysSample() { Age = 37});</param>
/// <returns></returns>
int BatchUpdate(Expression<Func<T, bool>> whereLambda, Expression<Func<T, T>> updateLambda);
Task<int> BatchUpdateAsync(Expression<Func<T, bool>> whereLambda, Expression<Func<T, T>> updateLambda);
#endregion
#region 刪除記錄 (異步和同步方法)
bool Delete(T model, bool isCommit = true);
Task<bool> DeleteAsync(T model, bool isCommit = true);
/// <summary>
/// 按主鍵刪除
/// </summary>
/// <param name="keyValues"></param>
int Delete(params object[] keyValues);
Task<int> DeleteAsync(params object[] keyValues);
/// <summary>
/// 批量刪除
/// </summary>
/// <param name="whereLambda">刪除條件</param>
/// <returns></returns>
int BatchDelete(Expression<Func<T, bool>> whereLambda);
Task<int> BatchDeleteAsync(Expression<Func<T, bool>> whereLambda);
#endregion
#region 查詢記錄(異步和同步方法)
T GetById(params object[] keyValues);
Task<T> GetByIdAsync(params object[] keyValues);
T GetSingleWhere(Expression<Func<T, bool>> whereLambda);
/// <summary>
/// 得到全部數據
/// </summary>
/// <returns></returns>
IQueryable<T> GetList();
/// <summary>
/// 根據表達式獲取數據
/// </summary>
/// <param name="whereLambda"></param>
/// <returns></returns>
IQueryable<T> GetList(Expression<Func<T, bool>> whereLambda);
IQueryable<T> GetList<S>(int pageSize, int pageIndex, out int total
, Expression<Func<T, bool>> whereLambda, bool isAsc, Expression<Func<T, bool>> orderByLambda);
#endregion
#region 執行數據庫語句 (同步和異步方法)
/// <summary>
/// 執行一條SQL語句
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
int ExecuteSqlCommand(string sql);
int ExecuteSqlCommand(string sql, params SqlParameter[] sp);
Task<int> ExecuteSqlCommandAsync(string sql);
IQueryable<T> SqlQuery(string sql);
IQueryable<T> SqlQuery(string sql, params object[] paras);
#endregion
bool IsExist(object id);
int SaveChanges();
}
}