IUnitWork.cs
2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Linq;
using System.Linq.Expressions;
namespace WebRepository
{
/// <summary>
/// 工作单元接口
/// <para> 适合在一下情况使用:</para>
/// <para>1 在同一事务中进行多表操作</para>
/// <para>2 需要多表联合查询</para>
/// <para>因为架构采用的是EF访问数据库,暂时可以不用考虑采用传统Unit Work的注册机制</para>
/// </summary>
public partial interface IUnitWork
{
BaseDBContext GetDbContext();
LoginInfo _loginInfo { get; set; }
T FindSingle<T>(Expression<Func<T, bool>> exp = null) where T : class;
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="exp"></param>
/// <returns>参数要检查是否为空的序列,返回Boolean 如果源序列包含任何元素,则为 true;否则为 false。</returns>
bool IsExist<T>(Expression<Func<T, bool>> exp) where T : class;
IQueryable<T> FindBySql<T>(string sql, params object[] parameters) 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;
void Add<T>(T entity) where T : class;
void BatchAdd<T>(T[] entities) where T : class;
/// <summary>
/// 更新一个实体的所有属性
/// </summary>
void Update<T>(T entity) where T : class;
void Delete<T>(T entity) where T : class;
void DeleteByTracking<T>(T entity) where T : SysEntity;
/// <summary>
/// 实现按需要只更新部分更新
/// <para>如:Update(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>
/// <typeparam name="T"></typeparam>
/// <param name="entity"></param>
void UpdateByTracking<T>(T entity) where T : SysEntity;
/// <summary>
/// 批量删除
/// </summary>
void Delete<T>(Expression<Func<T, bool>> exp) where T : class;
void Save();
int ExecuteSql(string sql);
/// <summary>
/// 获取任务号
/// </summary>
/// <param name="TaskType">TaskType.</param>
/// <param name="SeqLength">长度.</param>
string GetTaskNo(string TaskType, int SeqLength = 4);
}
}