首次推送
This commit is contained in:
105
Mtxfw.Utility/DataAccess/Insert.cs
Normal file
105
Mtxfw.Utility/DataAccess/Insert.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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 Insert<T>(T entity) where T : class, new()
|
||||
{
|
||||
return Db.Insertable(entity).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量插入
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体类名称</typeparam>
|
||||
/// <param name="entitys">实体类集合</param>
|
||||
/// <returns>插入并返回受影响行数</returns>
|
||||
public int Insert<T>(List<T> entitys) where T : class, new()
|
||||
{
|
||||
return Db.Insertable(entitys.ToArray()).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量插入
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体类名称</typeparam>
|
||||
/// <param name="dt">实体类集合</param>
|
||||
/// <returns>插入并返回受影响行数</returns>
|
||||
public int Insert<T>(Dictionary<string, object> dt) where T : class, new()
|
||||
{
|
||||
return Db.Insertable(dt).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只插入指定列数据
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体类名称</typeparam>
|
||||
/// <param name="entity">实体类</param>
|
||||
/// <param name="predicate">插入的指定列 -> it => new { it.Name, it.SchoolId }, 只插入列 Name和SchoolId</param>
|
||||
/// <returns></returns>
|
||||
public int InsertColumns<T>(T entity, Expression<Func<T, object>> predicate) where T : class, new()
|
||||
{
|
||||
return Db.Insertable(entity).InsertColumns(predicate).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只插入指定列数据(批量插入)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体类名称</typeparam>
|
||||
/// <param name="entity">实体类集合</param>
|
||||
/// <param name="predicate">插入的指定列 -> it => new { it.Name, it.SchoolId }, 只插入列 Name和SchoolId</param>
|
||||
/// <returns></returns>
|
||||
public int InsertColumns<T>(List<T> entitys, Expression<Func<T, object>> predicate) where T : class, new()
|
||||
{
|
||||
return Db.Insertable(entitys.ToArray()).InsertColumns(predicate).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 不插入指定列数据
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体类名称</typeparam>
|
||||
/// <param name="entity">实体类</param>
|
||||
/// <param name="predicate">插入的指定列 -> it => new { it.Name, it.SchoolId }, 只插入列 Name和SchoolId</param>
|
||||
/// <returns></returns>
|
||||
public int InsertIgnoreColumns<T>(T entity, Expression<Func<T, object>> predicate) where T : class, new()
|
||||
{
|
||||
return Db.Insertable(entity).IgnoreColumns(predicate).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 不插入指定列数据(批量插入)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体类名称</typeparam>
|
||||
/// <param name="entity">实体类集合</param>
|
||||
/// <param name="predicate">
|
||||
/// 插入的指定列 -> it => new { it.Name, it.SchoolId }, 只插入列 Name和SchoolId
|
||||
/// 或者 it => it == "Name" || it == "TestId"
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public int InsertIgnoreColumns<T>(List<T> entitys, Expression<Func<T, object>> predicate) where T : class, new()
|
||||
{
|
||||
return Db.Insertable(entitys.ToArray()).IgnoreColumns(predicate).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入一列数据
|
||||
/// </summary>
|
||||
public int InsertField<T>(Dictionary<string, object> dic) where T : class, new()
|
||||
{
|
||||
return Db.Insertable<T>(dic).ExecuteReturnIdentity();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user