86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Mtxfw.Utility.DataAccess
|
|
{
|
|
/// <summary>
|
|
/// 执行SQL或者存储过程类
|
|
/// </summary>
|
|
public partial class Sql : DbHelperSqlSugar
|
|
{
|
|
/// <summary>
|
|
/// 执行Sql语句和存储过程
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="sqlStr"></param>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public T SqlQuery<T>(string sqlStr, object obj) where T : class, new()
|
|
{
|
|
return Db.Ado.SqlQuery<T>(sqlStr, obj).SingleOrDefault();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行sql语句返回List
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="sqlStr"></param>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public List<T> SqlQueryList<T>(string sqlStr, object obj) where T : class, new()
|
|
{
|
|
return Db.Ado.SqlQuery<T>(sqlStr, obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行事务
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="sqlStr"></param>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public List<T> SqlQueryTran<T>(string sqlStr, object obj) where T : class, new()
|
|
{
|
|
var result = Db.Ado.UseTran<List<T>>(() =>
|
|
{
|
|
return Db.Ado.SqlQuery<T>(sqlStr, obj);
|
|
throw new Exception("error haha");
|
|
});
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行事务
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="sqlStr"></param>
|
|
/// <returns></returns>
|
|
public int SqlQueryTran(string sqlStr)
|
|
{
|
|
var result = Db.Ado.UseTran(() =>
|
|
{
|
|
return Db.Ado.ExecuteCommand(sqlStr);
|
|
throw new Exception("error haha");
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行事务
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="sqlStr"></param>
|
|
/// <returns></returns>
|
|
public int SqlQueryTran(string sqlStr, object param)
|
|
{
|
|
var result = Db.Ado.UseTran(() =>
|
|
{
|
|
return Db.Ado.ExecuteCommand(sqlStr, param);
|
|
throw new Exception("error haha");
|
|
});
|
|
return 0;
|
|
}
|
|
}
|
|
}
|