57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
|
|
using System;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace Mtxfw.Utility.DataAccess
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 删除类
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class Sql : DbHelperSqlSugar
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据实体类删除数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <typeparam name="T">实体类名称</typeparam>
|
|||
|
|
/// <param name="entity">实体类</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public int Del<T>(T entity) where T : class, new()
|
|||
|
|
{
|
|||
|
|
return Db.Deleteable<T>(entity).ExecuteCommand();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据主键删除数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <typeparam name="T">实体类名称</typeparam>
|
|||
|
|
/// <param name="keyValue">主键</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public int Del<T>(int keyValue) where T : class, new()
|
|||
|
|
{
|
|||
|
|
return Db.Deleteable<T>(keyValue).ExecuteCommand();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据主键批量删除
|
|||
|
|
/// </summary>
|
|||
|
|
/// <typeparam name="T">实体类名称</typeparam>
|
|||
|
|
/// <param name="keyValues">主键集合</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public int Del<T>(object[] keyValues) where T : class, new()
|
|||
|
|
{
|
|||
|
|
return Db.Deleteable<T>(keyValues).ExecuteCommand();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据条件删除
|
|||
|
|
/// </summary>
|
|||
|
|
/// <typeparam name="T">实体类名称</typeparam>
|
|||
|
|
/// <param name="predicate">linq 条件 -> (t => t.id == 1 && t.name == "aaaa")</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public int Del<T>(Expression<Func<T, bool>> predicate) where T : class, new()
|
|||
|
|
{
|
|||
|
|
return Db.Deleteable<T>(predicate).ExecuteCommand();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|