// *********************************************************************** // Assembly : OpenAuth.Domain // Author : yubaolee // Created : 10-25-2015 // // Last Modified By : yubaolee // Last Modified On : 10-25-2015 // *********************************************************************** // // Copyright (c) www.cnblogs.com/yubaolee. All rights reserved. // // 仓储接口 // *********************************************************************** using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; namespace Common.Interface { public interface IRepository where T : class where TDbContext : DbContext { /// /// 返回一个单独的实体,如果记录多于1个则取第一个 /// T FirstOrDefault(Expression> exp = null); /// /// 判断指定条件的记录是否存在 /// bool Any(Expression> exp); IQueryable Find(Expression> exp = null); IQueryable Find(int pageindex = 1, int pagesize = 10, string orderby = "", Expression> exp = null); int Count(Expression> exp = null); void Add(T entity); void BatchAdd(T[] entities); /// /// 更新一个实体的所有属性 /// void Update(T entity); void Delete(T entity); /// /// 实现按需要只更新部分更新 /// 如:Update(u =>u.Id==1,u =>new User{Name="ok"}); /// /// 更新条件 /// 更新后的实体 void Update(Expression> where, Expression> entity); /// /// 批量删除 /// void Delete(Expression> exp); void Save(); int ExecuteSqlRaw(string sql); /// /// 使用SQL脚本查询 /// /// T为数据库实体 /// IQueryable FromSql(string sql, params object[] parameters); /// /// 使用SQL脚本查询 /// /// T为非数据库实体,需要在DbContext中增加对应的DbQuery /// IQueryable Query(string sql, params object[] parameters); #region 异步接口 Task ExecuteSqlRawAsync(string sql); Task AddAsync(T entity); Task BatchAddAsync(T[] entities); Task UpdateAsync(T entity); Task DeleteAsync(T entity); Task SaveAsync(); Task CountAsync(Expression> exp = null); Task AnyAsync(Expression> exp); Task FirstOrDefaultAsync(Expression> exp); #endregion } }