数据库连接替换成IOC配置

This commit is contained in:
izory 2021-10-11 18:05:01 +08:00
parent d7bd6c9a7f
commit 8fe1fa1938
8 changed files with 229 additions and 209 deletions

View File

@ -7,7 +7,10 @@ namespace Infrastructure
public class OptionsSetting public class OptionsSetting
{ {
public static string ConnAdmin = "conn_zrAdmin"; public static string ConnAdmin = "conn_zrAdmin";
public static string ConnDbType = "conn_zrAdmin_Type"; public static string ConnDbType = "conn_zrAdmin_type";
public static string ConnBus = "conn_bus";
public static string ConnBusDbType = "conn_bus_type";
public static string DbKey = "DbKey"; public static string DbKey = "DbKey";
public string Redis { get; set; } public string Redis { get; set; }

View File

@ -11,7 +11,11 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using SqlSugar.IOC;
using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Admin.WebApi.Middleware; using ZR.Admin.WebApi.Middleware;
@ -116,12 +120,54 @@ namespace ZR.Admin.WebApi
/// ×¢²áServices·þÎñ /// ×¢²áServices·þÎñ
/// </summary> /// </summary>
/// <param name="services"></param> /// <param name="services"></param>
private static void InjectRepositories(IServiceCollection services) private void InjectRepositories(IServiceCollection services)
{ {
services.AddAppService(); services.AddAppService();
//¿ªÆô¼Æ»®ÈÎÎñ //¿ªÆô¼Æ»®ÈÎÎñ
services.AddTaskSchedulers(); services.AddTaskSchedulers();
string connStr = Configuration.GetConnectionString(OptionsSetting.ConnAdmin);
string connStrBus = Configuration.GetConnectionString(OptionsSetting.ConnBus);
string dbKey = Configuration[OptionsSetting.DbKey];
int dbType = Convert.ToInt32(Configuration[OptionsSetting.ConnDbType]);
int dbType_bus = Convert.ToInt32(Configuration[OptionsSetting.ConnBusDbType]);
IocConfig db1 = new IocConfig()
{
ConfigId = "0", //多租户用到
ConnectionString = connStr,
DbType = (IocDbType)dbType,
IsAutoCloseConnection = true//自动释放
};
IocConfig db2 = new IocConfig()
{
ConfigId = "1", // 多租户用到
ConnectionString = connStrBus,
DbType = (IocDbType)dbType_bus,
IsAutoCloseConnection = true//自动释放
};
SugarIocServices.AddSqlSugar(new List<IocConfig>() { db1, db2 });
//调式代码 用来打印SQL
DbScoped.SugarScope.GetConnection(0).Aop.OnLogExecuting = (sql, pars) =>
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n"
+ DbScoped.SugarScope.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
};
//出错打印日志
DbScoped.SugarScope.GetConnection(0).Aop.OnError = (e) =>
{
Console.WriteLine($"[执行Sql出错]{e.Message}SQL={e.Sql}");
Console.WriteLine();
};
//Bus Db错误日志
DbScoped.SugarScope.GetConnection(1).Aop.OnError = (e) =>
{
Console.WriteLine($"[执行Sql出错Bus]{e.Message}SQL={e.Sql}");
Console.WriteLine();
};
} }
} }
} }

View File

@ -32,6 +32,7 @@
<PackageReference Include="NLog" Version="4.7.5" /> <PackageReference Include="NLog" Version="4.7.5" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" /> <PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
<PackageReference Include="Snowflake.Core" Version="2.0.0" /> <PackageReference Include="Snowflake.Core" Version="2.0.0" />
<PackageReference Include="SqlSugar.IOC" Version="1.7.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageReference Include="UAParser" Version="3.1.46" /> <PackageReference Include="UAParser" Version="3.1.46" />
</ItemGroup> </ItemGroup>

View File

@ -7,9 +7,11 @@
} }
}, },
"ConnectionStrings": { "ConnectionStrings": {
"conn_zrAdmin": "server=127.0.0.1;user=zr;pwd=abc;database=admin" "conn_zrAdmin": "server=127.0.0.1;user=zr;pwd=abc;database=admin",
"conn_bus": "server=127.0.0.1;user=zr;pwd=abc;database=admin"
}, },
"conn_zrAdmin_Type": 0, //MySql = 0, SqlServer = 1 "conn_zrAdmin_type": 0, //MySql = 0, SqlServer = 1
"conn_bus_type": 0,
"urls": "http://localhost:8888", //url "urls": "http://localhost:8888", //url
"sysConfig": { "sysConfig": {
"DBCommandTimeout": 10, "DBCommandTimeout": 10,

View File

@ -1,6 +1,7 @@
using Infrastructure; using Infrastructure;
using Infrastructure.Model; using Infrastructure.Model;
using SqlSugar; using SqlSugar;
using SqlSugar.IOC;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Dynamic; using System.Dynamic;
@ -21,46 +22,8 @@ namespace ZR.Repository
{ {
if (dbContext == null) if (dbContext == null)
{ {
string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin); //Console.WriteLine("configId" + configId);
string dbKey = ConfigUtils.Instance.GetAppConfig<string>(OptionsSetting.DbKey); base.Context = DbScoped.SugarScope.GetConnection(configId);//根据类传入的ConfigId自动选择
int dbType = ConfigUtils.Instance.GetAppConfig<int>(OptionsSetting.ConnDbType);
if (!string.IsNullOrEmpty(dbKey))
{
connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey);
}
var Db = new SqlSugarClient(new List<ConnectionConfig>()
{
new ConnectionConfig(){
ConnectionString = connStr,
DbType = (DbType)dbType,
IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样
InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
ConfigId = 0
},
new ConnectionConfig(){
ConnectionString = "",
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
ConfigId = 1
},
});
//调式代码 用来打印SQL
Db.GetConnection(0).Aop.OnLogExecuting = (sql, pars) =>
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
};
//出错打印日志
Db.GetConnection(0).Aop.OnError = (e) =>
{
Console.WriteLine($"[执行Sql出错]{e.Message}SQL={e.Sql}");
Console.WriteLine();
};
Context = Db.GetConnection(configId);//根据类传入的ConfigId自动选择
} }
} }
@ -87,115 +50,115 @@ namespace ZR.Repository
return Context.Insertable(t).ExecuteCommand(); return Context.Insertable(t).ExecuteCommand();
} }
public int InsertIgnoreNullColumn(T t) //public int InsertIgnoreNullColumn(T t)
{ //{
return Context.Insertable(t).IgnoreColumns(true).ExecuteCommand(); // return Context.Insertable(t).IgnoreColumns(true).ExecuteCommand();
} //}
public int InsertIgnoreNullColumn(T t, params string[] columns) //public int InsertIgnoreNullColumn(T t, params string[] columns)
{ //{
return Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand(); // return Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand();
} //}
//public int Insert(SqlSugarClient client, T t) //public int Insert(SqlSugarClient client, T t)
//{ //{
// return client.Insertable(t).ExecuteCommand(); // return client.Insertable(t).ExecuteCommand();
//} //}
public long InsertBigIdentity(T t) //public long InsertBigIdentity(T t)
{ //{
return base.Context.Insertable(t).ExecuteReturnBigIdentity(); // return base.Context.Insertable(t).ExecuteReturnBigIdentity();
} //}
public int Insert(List<T> t) public int Insert(List<T> t)
{ {
return base.Context.Insertable(t).ExecuteCommand(); return base.Context.Insertable(t).ExecuteCommand();
} }
public int InsertIgnoreNullColumn(List<T> t) //public int InsertIgnoreNullColumn(List<T> t)
{ //{
return base.Context.Insertable(t).IgnoreColumns(true).ExecuteCommand(); // return base.Context.Insertable(t).IgnoreColumns(true).ExecuteCommand();
} //}
public int InsertIgnoreNullColumn(List<T> t, params string[] columns) //public int InsertIgnoreNullColumn(List<T> t, params string[] columns)
{ //{
return base.Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand(); // return base.Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand();
} //}
public int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true) //public int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
{ //{
return base.Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand(); // return base.Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
} //}
public DbResult<bool> InsertTran(T t) //public DbResult<bool> InsertTran(T t)
{ //{
var result = base.Context.Ado.UseTran(() => // var result = base.Context.Ado.UseTran(() =>
{ // {
base.Context.Insertable(t).ExecuteCommand(); // base.Context.Insertable(t).ExecuteCommand();
}); // });
return result; // return result;
} //}
public DbResult<bool> InsertTran(List<T> t) //public DbResult<bool> InsertTran(List<T> t)
{ //{
var result = base.Context.Ado.UseTran(() => // var result = base.Context.Ado.UseTran(() =>
{ // {
base.Context.Insertable(t).ExecuteCommand(); // base.Context.Insertable(t).ExecuteCommand();
}); // });
return result; // return result;
} //}
public T InsertReturnEntity(T t) //public T InsertReturnEntity(T t)
{ //{
return base.Context.Insertable(t).ExecuteReturnEntity(); // return base.Context.Insertable(t).ExecuteReturnEntity();
} //}
public T InsertReturnEntity(T t, string sqlWith = SqlWith.UpdLock) //public T InsertReturnEntity(T t, string sqlWith = SqlWith.UpdLock)
{ //{
return base.Context.Insertable(t).With(sqlWith).ExecuteReturnEntity(); // return base.Context.Insertable(t).With(sqlWith).ExecuteReturnEntity();
} //}
public bool ExecuteCommand(string sql, object parameters) //public bool ExecuteCommand(string sql, object parameters)
{ //{
return base.Context.Ado.ExecuteCommand(sql, parameters) > 0; // return base.Context.Ado.ExecuteCommand(sql, parameters) > 0;
} //}
public bool ExecuteCommand(string sql, params SugarParameter[] parameters) //public bool ExecuteCommand(string sql, params SugarParameter[] parameters)
{ //{
return base.Context.Ado.ExecuteCommand(sql, parameters) > 0; // return base.Context.Ado.ExecuteCommand(sql, parameters) > 0;
} //}
public bool ExecuteCommand(string sql, List<SugarParameter> parameters) //public bool ExecuteCommand(string sql, List<SugarParameter> parameters)
{ //{
return base.Context.Ado.ExecuteCommand(sql, parameters) > 0; // return base.Context.Ado.ExecuteCommand(sql, parameters) > 0;
} //}
#endregion add #endregion add
#region update #region update
public bool UpdateEntity(T entity, bool ignoreNullColumns = false) //public bool UpdateEntity(T entity, bool ignoreNullColumns = false)
{ //{
return base.Context.Updateable(entity).IgnoreColumns(ignoreNullColumns).ExecuteCommand() > 0; // return base.Context.Updateable(entity).IgnoreColumns(ignoreNullColumns).ExecuteCommand() > 0;
} //}
public bool Update(T entity, Expression<Func<T, bool>> expression) //public bool Update(T entity, Expression<Func<T, bool>> expression)
{ //{
return base.Context.Updateable(entity).Where(expression).ExecuteCommand() > 0; // return base.Context.Updateable(entity).Where(expression).ExecuteCommand() > 0;
} //}
public bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false) //public bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false)
{ //{
return base.Context.Updateable(entity).UpdateColumns(expression).IgnoreColumns(ignoreAllNull).ExecuteCommand() > 0; // return base.Context.Updateable(entity).UpdateColumns(expression).IgnoreColumns(ignoreAllNull).ExecuteCommand() > 0;
} //}
public bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where) //public bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where)
{ //{
return base.Context.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0; // return base.Context.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0;
} //}
public bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where) //public bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where)
{ //{
return client.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0; // return client.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0;
} //}
/// <summary> /// <summary>
/// ///
@ -218,14 +181,14 @@ namespace ZR.Repository
return base.Context.Updateable(entity).IgnoreColumns(isNull).IgnoreColumns(list.ToArray()).ExecuteCommand() > 0; return base.Context.Updateable(entity).IgnoreColumns(isNull).IgnoreColumns(list.ToArray()).ExecuteCommand() > 0;
} }
public bool Update(List<T> entity) //public bool Update(List<T> entity)
{ //{
var result = base.Context.Ado.UseTran(() => // var result = base.Context.Ado.UseTran(() =>
{ // {
base.Context.Updateable(entity).ExecuteCommand(); // base.Context.Updateable(entity).ExecuteCommand();
}); // });
return result.IsSuccess; // return result.IsSuccess;
} //}
public bool Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns) public bool Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns)
{ {
return base.Context.Updateable<T>().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand() > 0; return base.Context.Updateable<T>().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand() > 0;
@ -252,20 +215,20 @@ namespace ZR.Repository
#region delete #region delete
public bool DeleteExp(Expression<Func<T, bool>> expression) //public bool DeleteExp(Expression<Func<T, bool>> expression)
{ //{
return Context.Deleteable<T>().Where(expression).ExecuteCommand() > 0; // return Context.Deleteable<T>().Where(expression).ExecuteCommand() > 0;
} //}
//public bool Delete<PkType>(PkType[] primaryKeyValues) //public bool Delete<PkType>(PkType[] primaryKeyValues)
//{ //{
// return base.Context.Deleteable<T>().In(primaryKeyValues).ExecuteCommand() > 0; // return base.Context.Deleteable<T>().In(primaryKeyValues).ExecuteCommand() > 0;
//} //}
public int Delete(object[] obj) //public int Delete(object[] obj)
{ //{
return Context.Deleteable<T>().In(obj).ExecuteCommand(); // return Context.Deleteable<T>().In(obj).ExecuteCommand();
} //}
public int Delete(object id) public int Delete(object id)
{ {
return Context.Deleteable<T>(id).ExecuteCommand(); return Context.Deleteable<T>(id).ExecuteCommand();
@ -289,20 +252,20 @@ namespace ZR.Repository
return Context.Queryable<T>(); return Context.Queryable<T>();
} }
public ISugarQueryable<ExpandoObject> Queryable(string tableName, string shortName) //public ISugarQueryable<ExpandoObject> Queryable(string tableName, string shortName)
{ //{
return Context.Queryable(tableName, shortName); // return Context.Queryable(tableName, shortName);
} //}
public List<T> QueryableToList(Expression<Func<T, bool>> expression) public List<T> QueryableToList(Expression<Func<T, bool>> expression)
{ {
return Context.Queryable<T>().Where(expression).ToList(); return Context.Queryable<T>().Where(expression).ToList();
} }
public Task<List<T>> QueryableToListAsync(Expression<Func<T, bool>> expression) //public Task<List<T>> QueryableToListAsync(Expression<Func<T, bool>> expression)
{ //{
return Context.Queryable<T>().Where(expression).ToListAsync(); // return Context.Queryable<T>().Where(expression).ToListAsync();
} //}
//public string QueryableToJson(string select, Expression<Func<T, bool>> expressionWhere) //public string QueryableToJson(string select, Expression<Func<T, bool>> expressionWhere)
//{ //{
@ -310,45 +273,45 @@ namespace ZR.Repository
// return query.JilToJson(); // return query.JilToJson();
//} //}
public List<T> QueryableToList(string tableName) //public List<T> QueryableToList(string tableName)
{ //{
return Context.Queryable<T>(tableName).ToList(); // return Context.Queryable<T>(tableName).ToList();
} //}
public List<T> QueryableToList(string tableName, Expression<Func<T, bool>> expression) //public List<T> QueryableToList(string tableName, Expression<Func<T, bool>> expression)
{ //{
return Context.Queryable<T>(tableName).Where(expression).ToList(); // return Context.Queryable<T>(tableName).Where(expression).ToList();
} //}
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10) //public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10)
{ //{
int totalNumber = 0; // int totalNumber = 0;
var list = Context.Queryable<T>().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber); // var list = Context.Queryable<T>().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber);
return (list, totalNumber); // return (list, totalNumber);
} //}
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10) //public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10)
{ //{
int totalNumber = 0; // int totalNumber = 0;
var list = Context.Queryable<T>().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber); // var list = Context.Queryable<T>().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber);
return (list, totalNumber); // return (list, totalNumber);
} //}
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10) //public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10)
{ //{
int totalNumber = 0; // int totalNumber = 0;
if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase)) // if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase))
{ // {
var list = Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber); // var list = Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber);
return (list, totalNumber); // return (list, totalNumber);
} // }
else // else
{ // {
var list = Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber); // var list = Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber);
return (list, totalNumber); // return (list, totalNumber);
} // }
} //}
public List<T> SqlQueryToList(string sql, object obj = null) public List<T> SqlQueryToList(string sql, object obj = null)
{ {

View File

@ -18,42 +18,42 @@ namespace ZR.Repository
int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true); int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
int Add(T t); int Add(T t);
int InsertIgnoreNullColumn(T t); //int InsertIgnoreNullColumn(T t);
int InsertIgnoreNullColumn(T t, params string[] columns); //int InsertIgnoreNullColumn(T t, params string[] columns);
//int Insert(SqlSugarClient client, T t); //int Insert(SqlSugarClient client, T t);
long InsertBigIdentity(T t); //long InsertBigIdentity(T t);
int Insert(List<T> t); int Insert(List<T> t);
int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true); //int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
int InsertIgnoreNullColumn(List<T> t); //int InsertIgnoreNullColumn(List<T> t);
int InsertIgnoreNullColumn(List<T> t, params string[] columns); //int InsertIgnoreNullColumn(List<T> t, params string[] columns);
DbResult<bool> InsertTran(T t); //DbResult<bool> InsertTran(T t);
DbResult<bool> InsertTran(List<T> t); //DbResult<bool> InsertTran(List<T> t);
T InsertReturnEntity(T t); //T InsertReturnEntity(T t);
T InsertReturnEntity(T t, string sqlWith = SqlWith.UpdLock); //T InsertReturnEntity(T t, string sqlWith = SqlWith.UpdLock);
bool ExecuteCommand(string sql, object parameters); //bool ExecuteCommand(string sql, object parameters);
bool ExecuteCommand(string sql, params SugarParameter[] parameters); //bool ExecuteCommand(string sql, params SugarParameter[] parameters);
bool ExecuteCommand(string sql, List<SugarParameter> parameters); //bool ExecuteCommand(string sql, List<SugarParameter> parameters);
#endregion add #endregion add
#region update #region update
bool UpdateEntity(T entity, bool ignoreNullColumns = false); //bool UpdateEntity(T entity, bool ignoreNullColumns = false);
bool Update(T entity, Expression<Func<T, bool>> expression); //bool Update(T entity, Expression<Func<T, bool>> expression);
/// <summary> /// <summary>
/// 只更新表达式的值 /// 只更新表达式的值
@ -61,11 +61,11 @@ namespace ZR.Repository
/// <param name="entity"></param> /// <param name="entity"></param>
/// <param name="expression"></param> /// <param name="expression"></param>
/// <returns></returns> /// <returns></returns>
bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false); //bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false);
bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where); //bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where); //bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
/// <summary> /// <summary>
/// ///
@ -76,7 +76,7 @@ namespace ZR.Repository
/// <returns></returns> /// <returns></returns>
bool Update(T entity, List<string> list = null, bool isNull = true); bool Update(T entity, List<string> list = null, bool isNull = true);
bool Update(List<T> entity); //bool Update(List<T> entity);
bool Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns); bool Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns);
#endregion update #endregion update
@ -89,10 +89,10 @@ namespace ZR.Repository
#region delete #region delete
bool DeleteExp(Expression<Func<T, bool>> expression); //bool DeleteExp(Expression<Func<T, bool>> expression);
//bool Delete<PkType>(PkType[] primaryKeyValues); //bool Delete<PkType>(PkType[] primaryKeyValues);
int Delete(object[] obj); //int Delete(object[] obj);
int Delete(object id); int Delete(object id);
bool DeleteTable(); bool DeleteTable();
@ -120,19 +120,19 @@ namespace ZR.Repository
List<T> QueryableToList(Expression<Func<T, bool>> expression); List<T> QueryableToList(Expression<Func<T, bool>> expression);
Task<List<T>> QueryableToListAsync(Expression<Func<T, bool>> expression); //Task<List<T>> QueryableToListAsync(Expression<Func<T, bool>> expression);
//string QueryableToJson(string select, Expression<Func<T, bool>> expressionWhere); //string QueryableToJson(string select, Expression<Func<T, bool>> expressionWhere);
List<T> QueryableToList(string tableName); //List<T> QueryableToList(string tableName);
List<T> QueryableToList(string tableName, Expression<Func<T, bool>> expression); //List<T> QueryableToList(string tableName, Expression<Func<T, bool>> expression);
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10); //(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10);
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10); //(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10);
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10); //(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10);
//(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Bootstrap.BootstrapParams bootstrap); //(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Bootstrap.BootstrapParams bootstrap);

View File

@ -14,6 +14,10 @@ namespace ZR.Repository
[AppService(ServiceLifetime = LifeTime.Transient)] [AppService(ServiceLifetime = LifeTime.Transient)]
public class GendemoRepository : BaseRepository<Gendemo> public class GendemoRepository : BaseRepository<Gendemo>
{ {
public GendemoRepository() : base(configId: 1)
{
}
#region #region
#endregion #endregion
} }

View File

@ -13,6 +13,7 @@
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
<PackageReference Include="MySql.Data" Version="8.0.25" /> <PackageReference Include="MySql.Data" Version="8.0.25" />
<PackageReference Include="NETCore.Encrypt" Version="2.0.9" /> <PackageReference Include="NETCore.Encrypt" Version="2.0.9" />
<PackageReference Include="SqlSugar.IOC" Version="1.7.0" />
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.4" /> <PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.4" />
</ItemGroup> </ItemGroup>