// ***********************************************************************
// 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;
using OpenAuth.Repository.Core;
namespace OpenAuth.Repository.Interface
{
///
/// 工作单元接口
/// 适合在一下情况使用:
/// 1 在同一事务中进行多表操作
/// 2 需要多表联合查询
/// 因为架构采用的是EF访问数据库,暂时可以不用考虑采用传统Unit Work的注册机制
///
public interface IUnitWork
{
OpenAuthDBContext GetDbContext();
T FindSingle(Expression> exp = null) where T:class;
bool IsExist(Expression> exp) where T:class;
IQueryable Find(Expression> exp = null) where T:class;
IQueryable Find(int pageindex = 1, int pagesize = 10, string orderby = "",
Expression> exp = null) where T:class;
int GetCount(Expression> exp = null) where T:class;
void Add(T entity) where T:BaseEntity;
void BatchAdd(T[] entities) where T:BaseEntity;
///
/// 更新一个实体的所有属性
///
void Update(T entity) where T:class;
void Delete(T entity) where T:class;
///
/// 实现按需要只更新部分更新
/// 如:Update(u =>u.Id==1,u =>new User{Name="ok"}) where T:class;
///
/// 更新条件
/// 更新后的实体
void Update(Expression> where, Expression> entity) where T:class;
///
/// 批量删除
///
void Delete(Expression> exp) where T:class;
void Save();
int ExecuteSql(string sql);
///
/// 使用SQL脚本查询
///
/// T为数据库实体
///
IQueryable FromSql(string sql, params object[] parameters) where T:class;
///
/// 使用SQL脚本查询
///
/// T为非数据库实体,需要在DbContext中增加对应的DbQuery
///
IQueryable Query(string sql, params object[] parameters) where T : class;
}
}