OpenAuth.Net/OpenAuth.Repository/Interface/IRepository.cs

73 lines
2.5 KiB
C#
Raw Normal View History

// ***********************************************************************
2015-10-26 21:58:12 +08:00
// Assembly : OpenAuth.Domain
// Author : yubaolee
// Created : 10-25-2015
//
// Last Modified By : yubaolee
// Last Modified On : 10-25-2015
// ***********************************************************************
// <copyright file="IRepository.cs" company="www.cnblogs.com/yubaolee">
// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
// </copyright>
// <summary>仓储接口</summary>
// ***********************************************************************
using System;
using System.Linq;
using System.Linq.Expressions;
2017-11-29 20:49:14 +08:00
namespace OpenAuth.Repository.Interface
2015-10-26 21:58:12 +08:00
{
public interface IRepository<T> where T : class
{
T FindSingle(Expression<Func<T, bool>> exp = null);
2016-04-01 17:12:33 +08:00
bool IsExist(Expression<Func<T, bool>> exp);
2015-10-26 21:58:12 +08:00
IQueryable<T> Find(Expression<Func<T, bool>> exp = null);
IQueryable<T> Find(int pageindex = 1, int pagesize = 10, string orderby = "",
Expression<Func<T, bool>> exp = null);
int GetCount(Expression<Func<T, bool>> exp = null);
void Add(T entity);
2016-04-01 17:12:33 +08:00
void BatchAdd(T[] entities);
2015-11-06 22:56:26 +08:00
/// <summary>
/// 更新一个实体的所有属性
/// </summary>
2015-10-26 21:58:12 +08:00
void Update(T entity);
void Delete(T entity);
2015-10-30 23:14:31 +08:00
2016-04-01 17:12:33 +08:00
/// <summary>
/// 实现按需要只更新部分更新
/// <para>如Update(u =>u.Id==1,u =>new User{Name="ok"});</para>
/// </summary>
/// <param name="where">更新条件</param>
/// <param name="entity">更新后的实体</param>
void Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> entity);
2015-10-30 23:14:31 +08:00
/// <summary>
/// 批量删除
/// </summary>
void Delete(Expression<Func<T, bool>> exp);
2015-10-26 21:58:12 +08:00
void Save();
2018-03-02 17:45:08 +08:00
int ExecuteSql(string sql);
/// <summary>
/// 使用SQL脚本查询
/// </summary>
/// <typeparam name="T"> T为数据库实体</typeparam>
/// <returns></returns>
IQueryable<T> FromSql(string sql, params object[] parameters);
/// <summary>
/// 使用SQL脚本查询
/// </summary>
/// <typeparam name="T"> T为非数据库实体需要在DbContext中增加对应的DbQuery</typeparam>
/// <returns></returns>
IQueryable<T> Query(string sql, params object[] parameters);
2015-10-26 21:58:12 +08:00
}
}