2016-04-29 16:26:09 +08:00
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
// Assembly : OpenAuth.Domain
|
|
|
|
|
|
// Author : yubaolee
|
|
|
|
|
|
// Created : 04-29-2016
|
|
|
|
|
|
//
|
|
|
|
|
|
// Last Modified By : yubaolee
|
|
|
|
|
|
// Last Modified On : 04-29-2016
|
|
|
|
|
|
// Contact : Microsoft
|
|
|
|
|
|
// File: IUnitWork.cs
|
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Linq.Expressions;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using OpenAuth.Repository.Core;
|
2016-04-29 16:26:09 +08:00
|
|
|
|
|
2017-11-29 20:49:14 +08:00
|
|
|
|
namespace OpenAuth.Repository.Interface
|
2016-04-29 16:26:09 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 工作单元接口
|
|
|
|
|
|
/// <para> 适合在一下情况使用:</para>
|
|
|
|
|
|
/// <para>1 在同一事务中进行多表操作</para>
|
|
|
|
|
|
/// <para>2 需要多表联合查询</para>
|
|
|
|
|
|
/// <para>因为架构采用的是EF访问数据库,暂时可以不用考虑采用传统Unit Work的注册机制</para>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public interface IUnitWork
|
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
OpenAuthDBContext GetDbContext();
|
2016-04-29 16:26:09 +08:00
|
|
|
|
T FindSingle<T>(Expression<Func<T, bool>> exp = null) where T:class;
|
|
|
|
|
|
bool IsExist<T>(Expression<Func<T, bool>> exp) where T:class;
|
|
|
|
|
|
IQueryable<T> Find<T>(Expression<Func<T, bool>> exp = null) where T:class;
|
|
|
|
|
|
|
|
|
|
|
|
IQueryable<T> Find<T>(int pageindex = 1, int pagesize = 10, string orderby = "",
|
|
|
|
|
|
Expression<Func<T, bool>> exp = null) where T:class;
|
|
|
|
|
|
|
|
|
|
|
|
int GetCount<T>(Expression<Func<T, bool>> exp = null) where T:class;
|
|
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
void Add<T>(T entity) where T:BaseEntity;
|
2016-04-29 16:26:09 +08:00
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
void BatchAdd<T>(T[] entities) where T:BaseEntity;
|
2016-04-29 16:26:09 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新一个实体的所有属性
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
void Update<T>(T entity) where T:class;
|
|
|
|
|
|
|
|
|
|
|
|
void Delete<T>(T entity) where T:class;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 实现按需要只更新部分更新
|
|
|
|
|
|
/// <para>如:Update<T>(u =>u.Id==1,u =>new User{Name="ok"}) where T:class;</para>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="where">更新条件</param>
|
|
|
|
|
|
/// <param name="entity">更新后的实体</param>
|
|
|
|
|
|
void Update<T>(Expression<Func<T, bool>> where, Expression<Func<T, T>> entity) where T:class;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量删除
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
void Delete<T>(Expression<Func<T, bool>> exp) where T:class;
|
|
|
|
|
|
|
|
|
|
|
|
void Save();
|
|
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
int ExecuteSql(string sql);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 使用SQL脚本查询
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"> T为数据库实体</typeparam>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
IQueryable<T> FromSql<T>(string sql, params object[] parameters) where T:class;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 使用SQL脚本查询
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"> T为非数据库实体,需要在DbContext中增加对应的DbQuery</typeparam>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
IQueryable<T> Query<T>(string sql, params object[] parameters) where T : class;
|
2016-04-29 16:26:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|