mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Synchronization code
This commit is contained in:
parent
38c4499a52
commit
2cc582546f
@ -1578,7 +1578,18 @@ namespace SqlSugar
|
||||
var tableinfo = this.QueryBuilder.AsTables.First();
|
||||
if (this.QueryBuilder.TableWithString != SqlWith.Null && this.Context.CurrentConnectionConfig?.MoreSettings?.IsWithNoLockQuery == true && this.QueryBuilder.AsTables.First().Value.ObjToString().Contains(SqlWith.NoLock) == false)
|
||||
{
|
||||
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + $" {SqlWith.NoLock} )";
|
||||
if (this.QueryBuilder.AsTables.First().Value.EndsWith(") unionTable "))
|
||||
{
|
||||
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + ")";
|
||||
}
|
||||
else if (this.QueryBuilder.AsTables.First().Value.EndsWith(") MergeTable "))
|
||||
{
|
||||
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + $" {SqlWith.NoLock} )";
|
||||
}
|
||||
}
|
||||
else if (this.QueryBuilder.IsSqlQuery && this.QueryBuilder.AsTables.First().Value.ObjToString().StartsWith("("))
|
||||
{
|
||||
|
@ -1453,6 +1453,7 @@ namespace SqlSugar
|
||||
return Select(expression);
|
||||
}
|
||||
var clone = this.Select(expression).Clone();
|
||||
clone.QueryBuilder.IsDistinct = false;
|
||||
//clone.QueryBuilder.LambdaExpressions.Index = QueryBuilder.LambdaExpressions.Index+1;
|
||||
var ps = clone.QueryBuilder;
|
||||
var sql = ps.GetSelectValue;
|
||||
|
@ -176,6 +176,7 @@ namespace SqlSugar
|
||||
builder.Replace(" OR ( AND", " OR ( ");
|
||||
builder.Replace(" ( AND ", " ( ");
|
||||
builder.Replace(" ( OR ", " ( ");
|
||||
builder.Replace(" OR AND ", " OR ");
|
||||
}
|
||||
}
|
||||
parameters.AddRange(childSqlInfo.Value);
|
||||
|
@ -27,12 +27,25 @@ namespace SqlSugar
|
||||
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
||||
{
|
||||
var addList = item.Select(it => it.Item).ToList();
|
||||
result += this.Context.Updateable(addList)
|
||||
if (IsVersion())
|
||||
{
|
||||
Check.ExceptionEasy(addList.Count > 1, "The version number can only be used for single record updates", "版本号只能用于单条记录更新");
|
||||
result += this.Context.Updateable(addList.First())
|
||||
.WhereColumns(this.WhereColumns?.ToArray())
|
||||
.EnableDiffLogEventIF(this.IsEnableDiffLogEvent,this.BusinessData)
|
||||
.EnableDiffLogEventIF(this.IsEnableDiffLogEvent, this.BusinessData)
|
||||
.UpdateColumns(updateobj.UpdateBuilder.UpdateColumns?.ToArray())
|
||||
.IgnoreColumns(this.updateobj.UpdateBuilder.IsNoUpdateNull, this.updateobj.UpdateBuilder.IsOffIdentity, this.updateobj.UpdateBuilder.IsNoUpdateDefaultValue)
|
||||
.IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommandWithOptLock(isThrowError);
|
||||
}
|
||||
else
|
||||
{
|
||||
result += this.Context.Updateable(addList)
|
||||
.WhereColumns(this.WhereColumns?.ToArray())
|
||||
.EnableDiffLogEventIF(this.IsEnableDiffLogEvent, this.BusinessData)
|
||||
.UpdateColumns(updateobj.UpdateBuilder.UpdateColumns?.ToArray())
|
||||
.IgnoreColumns(this.updateobj.UpdateBuilder.IsNoUpdateNull, this.updateobj.UpdateBuilder.IsOffIdentity, this.updateobj.UpdateBuilder.IsNoUpdateDefaultValue)
|
||||
.IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommandWithOptLock(isThrowError);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -80,12 +93,26 @@ namespace SqlSugar
|
||||
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
||||
{
|
||||
var addList = item.Select(it => it.Item).ToList();
|
||||
result += await this.Context.Updateable(addList)
|
||||
.WhereColumns(this.WhereColumns?.ToArray())
|
||||
.EnableDiffLogEventIF(this.IsEnableDiffLogEvent, this.BusinessData)
|
||||
.UpdateColumns(updateobj.UpdateBuilder.UpdateColumns?.ToArray())
|
||||
.IgnoreColumns(this.updateobj.UpdateBuilder.IsNoUpdateNull, this.updateobj.UpdateBuilder.IsOffIdentity, this.updateobj.UpdateBuilder.IsNoUpdateDefaultValue)
|
||||
.IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommandWithOptLockAsync(isThrowError);
|
||||
if (IsVersion())
|
||||
{
|
||||
Check.ExceptionEasy(addList.Count > 1, "The version number can only be used for single record updates", "版本号只能用于单条记录更新");
|
||||
result += await this.Context.Updateable(addList.First())
|
||||
.WhereColumns(this.WhereColumns?.ToArray())
|
||||
.EnableDiffLogEventIF(this.IsEnableDiffLogEvent, this.BusinessData)
|
||||
.UpdateColumns(updateobj.UpdateBuilder.UpdateColumns?.ToArray())
|
||||
.IgnoreColumns(this.updateobj.UpdateBuilder.IsNoUpdateNull, this.updateobj.UpdateBuilder.IsOffIdentity, this.updateobj.UpdateBuilder.IsNoUpdateDefaultValue)
|
||||
.IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommandWithOptLockAsync(isThrowError);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
result += await this.Context.Updateable(addList)
|
||||
.WhereColumns(this.WhereColumns?.ToArray())
|
||||
.EnableDiffLogEventIF(this.IsEnableDiffLogEvent, this.BusinessData)
|
||||
.UpdateColumns(updateobj.UpdateBuilder.UpdateColumns?.ToArray())
|
||||
.IgnoreColumns(this.updateobj.UpdateBuilder.IsNoUpdateNull, this.updateobj.UpdateBuilder.IsOffIdentity, this.updateobj.UpdateBuilder.IsNoUpdateDefaultValue)
|
||||
.IgnoreColumns(GetIgnoreColumns()).AS(item.Key).ExecuteCommandWithOptLockAsync(isThrowError);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -117,6 +144,11 @@ namespace SqlSugar
|
||||
}
|
||||
result = 0;
|
||||
}
|
||||
private bool IsVersion()
|
||||
{
|
||||
return this.Context.EntityMaintenance.GetEntityInfo<T>().Columns.Any(it => it.IsEnableUpdateVersionValidation);
|
||||
}
|
||||
|
||||
internal class GroupModel
|
||||
{
|
||||
public string GroupName { get; set; }
|
||||
|
@ -98,6 +98,10 @@ namespace SqlSugar
|
||||
}
|
||||
private bool UpdateObjectNotWhere()
|
||||
{
|
||||
if (this.Context?.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.SqlServer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.Context.CurrentConnectionConfig.DbType != DbType.MySql
|
||||
&& this.Context.CurrentConnectionConfig.DbType != DbType.MySqlConnector
|
||||
&& this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer;
|
||||
@ -294,6 +298,10 @@ namespace SqlSugar
|
||||
|
||||
private void DataChangesAop(T [] items)
|
||||
{
|
||||
if (typeof(T).FullName.StartsWith("System.Collections.Generic.Dictionary`"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataChangesExecuted;
|
||||
if (dataEvent != null)
|
||||
{
|
||||
|
@ -251,6 +251,22 @@ namespace SqlSugar
|
||||
{
|
||||
return new OracleUpdateable<T>();
|
||||
}
|
||||
else if (IsCustomDb(currentConnectionConfig))
|
||||
{
|
||||
var name =
|
||||
"SqlSugar." + currentConnectionConfig.DbType +
|
||||
"." + currentConnectionConfig.DbType
|
||||
+ "Updateable`1";
|
||||
var type = GetCustomTypeByClass<T>(name);
|
||||
if (type == null)
|
||||
{
|
||||
return new UpdateableProvider<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (UpdateableProvider<T>)Activator.CreateInstance(type, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new UpdateableProvider<T>();
|
||||
@ -263,6 +279,22 @@ namespace SqlSugar
|
||||
{
|
||||
return new OracleDeleteable<T>();
|
||||
}
|
||||
else if (IsCustomDb(currentConnectionConfig))
|
||||
{
|
||||
var name =
|
||||
"SqlSugar." + currentConnectionConfig.DbType +
|
||||
"." + currentConnectionConfig.DbType
|
||||
+ "Deleteable`1";
|
||||
var type = GetCustomTypeByClass<T>(name);
|
||||
if (type == null)
|
||||
{
|
||||
return new DeleteableProvider<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (DeleteableProvider<T>)Activator.CreateInstance(type, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DeleteableProvider<T>();
|
||||
|
@ -36,5 +36,6 @@ namespace SqlSugar
|
||||
public static object DynamicExpressionParsingConfig;
|
||||
public static Action<ICacheService, string> CacheRemoveByLikeStringFunc { get; set; }
|
||||
public static Guid TableQuerySqlKey { get; set; }
|
||||
public static string BulkCopy_MySqlCsvPath { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace SqlSugar
|
||||
RepositoryType CopyNew<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository;
|
||||
RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository;
|
||||
SimpleClient<ChangeType> Change<ChangeType>() where ChangeType : class, new();
|
||||
RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository ;
|
||||
RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository;
|
||||
RepositoryType ChangeRepository<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository;
|
||||
IDeleteable<T> AsDeleteable();
|
||||
IInsertable<T> AsInsertable(List<T> insertObjs);
|
||||
@ -26,7 +26,9 @@ namespace SqlSugar
|
||||
IUpdateable<T> AsUpdateable();
|
||||
IUpdateable<T> AsUpdateable(T[] updateObjs);
|
||||
int Count(Expression<Func<T, bool>> whereExpression);
|
||||
int Count(List<IConditionalModel> conditionalModels);
|
||||
bool Delete(Expression<Func<T, bool>> whereExpression);
|
||||
bool Delete(List<IConditionalModel> conditionalModels);
|
||||
bool Delete(T deleteObj);
|
||||
bool Delete(List<T> deleteObjs);
|
||||
bool DeleteById(dynamic id);
|
||||
@ -34,12 +36,20 @@ namespace SqlSugar
|
||||
T GetById(dynamic id);
|
||||
List<T> GetList();
|
||||
List<T> GetList(Expression<Func<T, bool>> whereExpression);
|
||||
List<T> GetList(List<IConditionalModel> conditionalList);
|
||||
List<T> GetList(Expression<Func<T, bool>> whereExpression, List<OrderByModel> orderByModels);
|
||||
List<T> GetList(List<IConditionalModel> conditionalList, List<OrderByModel> orderByModels);
|
||||
List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page);
|
||||
List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, List<OrderByModel> orderByModels);
|
||||
List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc);
|
||||
List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page);
|
||||
List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page, List<OrderByModel> orderByModels);
|
||||
List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc);
|
||||
T GetSingle(Expression<Func<T, bool>> whereExpression);
|
||||
T GetSingle(List<IConditionalModel> conditionalModels);
|
||||
T GetFirst(Expression<Func<T, bool>> whereExpression);
|
||||
T GetFirst(List<IConditionalModel> conditionalModels);
|
||||
T GetFirst(List<IConditionalModel> conditionalModels, List<OrderByModel> orderByModels);
|
||||
bool Insert(T insertObj);
|
||||
bool InsertOrUpdate(T data);
|
||||
bool InsertOrUpdate(List<T> datas);
|
||||
@ -53,6 +63,7 @@ namespace SqlSugar
|
||||
|
||||
|
||||
bool IsAny(Expression<Func<T, bool>> whereExpression);
|
||||
bool IsAny(List<IConditionalModel> conditionalModels);
|
||||
bool Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
bool UpdateSetColumnsTrue(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
bool Update(T updateObj);
|
||||
@ -105,12 +116,12 @@ namespace SqlSugar
|
||||
Task<bool> DeleteByIdAsync(dynamic id, CancellationToken cancellationToken);
|
||||
Task<bool> DeleteByIdsAsync(dynamic[] ids, CancellationToken cancellationToken);
|
||||
Task<T> GetByIdAsync(dynamic id, CancellationToken cancellationToken);
|
||||
Task<List<T>> GetListAsync( CancellationToken cancellationToken);
|
||||
Task<List<T>> GetListAsync(CancellationToken cancellationToken);
|
||||
Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, CancellationToken cancellationToken);
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default);
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken = default);
|
||||
Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, CancellationToken cancellationToken);
|
||||
Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default);
|
||||
Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken = default);
|
||||
Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken);
|
||||
Task<bool> InsertAsync(T insertObj, CancellationToken cancellationToken);
|
||||
|
@ -9,6 +9,7 @@ namespace SqlSugar
|
||||
{
|
||||
public interface ITenant
|
||||
{
|
||||
string[] GetCurrentConfigIds();
|
||||
void BeginTran();
|
||||
void BeginTran(IsolationLevel iso);
|
||||
void CommitTran();
|
||||
|
@ -13,7 +13,7 @@ namespace SqlSugar
|
||||
{
|
||||
private static bool IsJoin(string name)
|
||||
{
|
||||
return name.StartsWith("LeftJoin".ToLower()) || name.StartsWith("RightJoin".ToLower()) || name.StartsWith("InnertJoin".ToLower());
|
||||
return name.StartsWith("LeftJoin".ToLower()) || name.StartsWith("RightJoin".ToLower()) || name.StartsWith("InnerJoin".ToLower());
|
||||
}
|
||||
private static bool IsJoinLastAfter(string name)
|
||||
{
|
||||
|
@ -9,16 +9,16 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
|
||||
public partial class SimpleClient<T> : ISugarRepository,ISimpleClient<T> where T : class, new()
|
||||
|
||||
public partial class SimpleClient<T> : ISugarRepository, ISimpleClient<T> where T : class, new()
|
||||
{
|
||||
#region Interface
|
||||
public ISqlSugarClient Context { get; set; }
|
||||
public virtual ISqlSugarClient Context { get; set; }
|
||||
|
||||
public ITenant AsTenant()
|
||||
public virtual ITenant AsTenant()
|
||||
{
|
||||
var result= this.Context as ITenant;
|
||||
if (result == null&& this.Context is SqlSugarProvider)
|
||||
var result = this.Context as ITenant;
|
||||
if (result == null && this.Context is SqlSugarProvider)
|
||||
{
|
||||
result = (this.Context as SqlSugarProvider).Root as ITenant;
|
||||
}
|
||||
@ -28,7 +28,7 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ISqlSugarClient AsSugarClient()
|
||||
public virtual ISqlSugarClient AsSugarClient()
|
||||
{
|
||||
return this.Context;
|
||||
}
|
||||
@ -45,21 +45,21 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.GetSimpleClient<ChangeType>();
|
||||
}
|
||||
public SimpleClient<T> CopyNew()
|
||||
public SimpleClient<T> CopyNew()
|
||||
{
|
||||
SimpleClient<T> sm = new SimpleClient<T>();
|
||||
sm.Context = this.Context.CopyNew();
|
||||
return sm;
|
||||
}
|
||||
public RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
public virtual RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
{
|
||||
Type type = typeof(RepositoryType);
|
||||
var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any());
|
||||
object o = null;
|
||||
if (isAnyParamter)
|
||||
{
|
||||
object[] pars= type.GetConstructors().First().GetParameters()
|
||||
.Select(it=>(object)null).ToArray();
|
||||
object[] pars = type.GetConstructors().First().GetParameters()
|
||||
.Select(it => (object)null).ToArray();
|
||||
o = Activator.CreateInstance(type, pars);
|
||||
}
|
||||
else
|
||||
@ -77,13 +77,13 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public RepositoryType CopyNew<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository
|
||||
public virtual RepositoryType CopyNew<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository
|
||||
{
|
||||
var instance = handleDependencies(typeof(RepositoryType), serviceProvider,true);
|
||||
var instance = handleDependencies(typeof(RepositoryType), serviceProvider, true);
|
||||
return (RepositoryType)instance;
|
||||
}
|
||||
|
||||
private object handleDependencies(Type type, IServiceProvider serviceProvider,bool needNewCopy = false)
|
||||
private object handleDependencies(Type type, IServiceProvider serviceProvider, bool needNewCopy = false)
|
||||
{
|
||||
ConstructorInfo constructorInfo = null;
|
||||
var newInstanceType = type;
|
||||
@ -129,7 +129,7 @@ namespace SqlSugar
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
private ISugarRepository setContext(ISugarRepository sugarRepository,bool needNewCopy)
|
||||
private ISugarRepository setContext(ISugarRepository sugarRepository, bool needNewCopy)
|
||||
{
|
||||
if (sugarRepository.Context != null)
|
||||
{
|
||||
@ -169,67 +169,67 @@ namespace SqlSugar
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
public virtual RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
{
|
||||
Type type = typeof(RepositoryType);
|
||||
var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any());
|
||||
object o = null;
|
||||
if (isAnyParamter)
|
||||
{
|
||||
o=Activator.CreateInstance(type, new string[] { null });
|
||||
o = Activator.CreateInstance(type, new string[] { null });
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
o = Activator.CreateInstance(type);
|
||||
}
|
||||
var result= (RepositoryType)o;
|
||||
var result = (RepositoryType)o;
|
||||
if (result.Context == null)
|
||||
{
|
||||
result.Context = this.Context;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public RepositoryType ChangeRepository<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository
|
||||
public virtual RepositoryType ChangeRepository<RepositoryType>(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository
|
||||
{
|
||||
var instance = handleDependencies(typeof(RepositoryType), serviceProvider, false);
|
||||
return (RepositoryType)instance;
|
||||
}
|
||||
public ISugarQueryable<T> AsQueryable()
|
||||
public virtual ISugarQueryable<T> AsQueryable()
|
||||
{
|
||||
return Context.Queryable<T>();
|
||||
}
|
||||
public IInsertable<T> AsInsertable(T insertObj)
|
||||
public virtual IInsertable<T> AsInsertable(T insertObj)
|
||||
{
|
||||
return Context.Insertable<T>(insertObj);
|
||||
}
|
||||
public IInsertable<T> AsInsertable(T[] insertObjs)
|
||||
public virtual IInsertable<T> AsInsertable(T[] insertObjs)
|
||||
{
|
||||
return Context.Insertable<T>(insertObjs);
|
||||
}
|
||||
public IInsertable<T> AsInsertable(List<T> insertObjs)
|
||||
public virtual IInsertable<T> AsInsertable(List<T> insertObjs)
|
||||
{
|
||||
return Context.Insertable<T>(insertObjs);
|
||||
}
|
||||
public IUpdateable<T> AsUpdateable(T updateObj)
|
||||
public virtual IUpdateable<T> AsUpdateable(T updateObj)
|
||||
{
|
||||
return Context.Updateable<T>(updateObj);
|
||||
}
|
||||
public IUpdateable<T> AsUpdateable(T[] updateObjs)
|
||||
public virtual IUpdateable<T> AsUpdateable(T[] updateObjs)
|
||||
{
|
||||
return Context.Updateable<T>(updateObjs);
|
||||
}
|
||||
public IUpdateable<T> AsUpdateable(List<T> updateObjs)
|
||||
public virtual IUpdateable<T> AsUpdateable(List<T> updateObjs)
|
||||
{
|
||||
return Context.Updateable<T>(updateObjs);
|
||||
}
|
||||
public IUpdateable<T> AsUpdateable()
|
||||
public virtual IUpdateable<T> AsUpdateable()
|
||||
{
|
||||
return Context.Updateable<T>();
|
||||
}
|
||||
public IDeleteable<T> AsDeleteable()
|
||||
public virtual IDeleteable<T> AsDeleteable()
|
||||
{
|
||||
return Context.Deleteable<T>();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Method
|
||||
@ -250,7 +250,7 @@ namespace SqlSugar
|
||||
{
|
||||
return Context.Queryable<T>().Single(whereExpression);
|
||||
}
|
||||
public virtual T GetFirst(Expression<Func<T, bool>> whereExpression)
|
||||
public virtual T GetFirst(Expression<Func<T, bool>> whereExpression)
|
||||
{
|
||||
return Context.Queryable<T>().First(whereExpression);
|
||||
}
|
||||
@ -297,7 +297,7 @@ namespace SqlSugar
|
||||
return this.Context.Insertable(insertObj).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
public virtual bool InsertOrUpdate(T data)
|
||||
public virtual bool InsertOrUpdate(T data)
|
||||
{
|
||||
return this.Context.Storageable(data).ExecuteCommand() > 0;
|
||||
}
|
||||
@ -324,11 +324,11 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual Task<long> InsertReturnSnowflakeIdAsync(T insertObj)
|
||||
{
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnSnowflakeIdAsync();
|
||||
return this.Context.Insertable(insertObj).ExecuteReturnSnowflakeIdAsync();
|
||||
}
|
||||
public virtual Task<List<long>> InsertReturnSnowflakeIdAsync(List<T> insertObjs)
|
||||
{
|
||||
return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync();
|
||||
return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync();
|
||||
}
|
||||
|
||||
public virtual T InsertReturnEntity(T insertObj)
|
||||
@ -362,7 +362,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual bool UpdateSetColumnsTrue(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression)
|
||||
{
|
||||
return this.Context.Updateable<T>().SetColumns(columns,true).Where(whereExpression).ExecuteCommand() > 0;
|
||||
return this.Context.Updateable<T>().SetColumns(columns, true).Where(whereExpression).ExecuteCommand() > 0;
|
||||
}
|
||||
public virtual bool Delete(T deleteObj)
|
||||
{
|
||||
@ -411,28 +411,28 @@ namespace SqlSugar
|
||||
public virtual async Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page)
|
||||
{
|
||||
RefAsync<int> count = 0;
|
||||
var result =await Context.Queryable<T>().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
var result = await Context.Queryable<T>().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual async Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
||||
{
|
||||
RefAsync<int> count = 0;
|
||||
var result =await Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
var result = await Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual async Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page)
|
||||
{
|
||||
RefAsync<int> count = 0;
|
||||
var result =await Context.Queryable<T>().Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
var result = await Context.Queryable<T>().Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual async Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
||||
{
|
||||
RefAsync<int> count = 0;
|
||||
var result =await Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
var result = await Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
@ -456,7 +456,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual async Task<bool> InsertAsync(T insertObj)
|
||||
{
|
||||
return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
|
||||
return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual Task<int> InsertReturnIdentityAsync(T insertObj)
|
||||
{
|
||||
@ -496,7 +496,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual async Task<bool> UpdateSetColumnsTrueAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression)
|
||||
{
|
||||
return await this.Context.Updateable<T>().SetColumns(columns,true).Where(whereExpression).ExecuteCommandAsync() > 0;
|
||||
return await this.Context.Updateable<T>().SetColumns(columns, true).Where(whereExpression).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public virtual async Task<bool> DeleteAsync(T deleteObj)
|
||||
{
|
||||
@ -532,9 +532,9 @@ namespace SqlSugar
|
||||
return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync();
|
||||
}
|
||||
|
||||
public virtual Task<T> GetByIdAsync(dynamic id,CancellationToken cancellationToken)
|
||||
public virtual Task<T> GetByIdAsync(dynamic id, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Context.Ado.CancellationToken= cancellationToken;
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return Context.Queryable<T>().InSingleAsync(id);
|
||||
}
|
||||
public virtual Task<List<T>> GetListAsync(CancellationToken cancellationToken)
|
||||
@ -582,7 +582,7 @@ namespace SqlSugar
|
||||
page.TotalCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual async Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken=default)
|
||||
public virtual async Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken = default)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
RefAsync<int> count = 0;
|
||||
@ -691,6 +691,73 @@ namespace SqlSugar
|
||||
this.Context.Ado.CancellationToken = cancellationToken;
|
||||
return await this.Context.Deleteable<T>().In(ids).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
public int Count(List<IConditionalModel> conditionalModels)
|
||||
{
|
||||
return Context.Queryable<T>().Where(conditionalModels).Count();
|
||||
}
|
||||
|
||||
public bool Delete(List<IConditionalModel> conditionalModels)
|
||||
{
|
||||
return Context.Deleteable<T>().Where(conditionalModels).ExecuteCommandHasChange();
|
||||
}
|
||||
|
||||
public List<T> GetList(Expression<Func<T, bool>> whereExpression, List<OrderByModel> orderByModels)
|
||||
{
|
||||
return Context.Queryable<T>().Where(whereExpression).OrderBy(orderByModels).ToList();
|
||||
}
|
||||
|
||||
public List<T> GetList(List<IConditionalModel> conditionalList)
|
||||
{
|
||||
return Context.Queryable<T>().Where(conditionalList).ToList();
|
||||
}
|
||||
|
||||
public List<T> GetList(List<IConditionalModel> conditionalList, List<OrderByModel> orderByModels)
|
||||
{
|
||||
return Context.Queryable<T>().Where(conditionalList).OrderBy(orderByModels).ToList();
|
||||
}
|
||||
|
||||
public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, List<OrderByModel> orderByModels)
|
||||
{
|
||||
var total = 0;
|
||||
var list = Context.Queryable<T>().Where(whereExpression).OrderBy(orderByModels).ToPageList(page.PageIndex, page.PageSize, ref total);
|
||||
page.TotalCount = total;
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<T> GetPageList(List<IConditionalModel> conditionalList, PageModel page, List<OrderByModel> orderByModels)
|
||||
{
|
||||
var total = 0;
|
||||
var list = Context.Queryable<T>().Where(conditionalList).OrderBy(orderByModels).ToPageList(page.PageIndex, page.PageSize, ref total);
|
||||
page.TotalCount = total;
|
||||
return list;
|
||||
}
|
||||
|
||||
public T GetSingle(List<IConditionalModel> conditionalModels)
|
||||
{
|
||||
return Context.Queryable<T>().Where(conditionalModels).Single();
|
||||
}
|
||||
|
||||
public T GetFirst(List<IConditionalModel> conditionalModels)
|
||||
{
|
||||
return Context.Queryable<T>().Where(conditionalModels).First();
|
||||
}
|
||||
|
||||
public bool IsAny(List<IConditionalModel> conditionalModels)
|
||||
{
|
||||
return Context.Queryable<T>().Where(conditionalModels).Any();
|
||||
}
|
||||
|
||||
public T GetFirst(Expression<Func<T, bool>> whereExpression, List<OrderByModel> orderByModels)
|
||||
{
|
||||
return Context.Queryable<T>().Where(whereExpression).OrderBy(orderByModels).First();
|
||||
}
|
||||
|
||||
public T GetFirst(List<IConditionalModel> conditionalModels, List<OrderByModel> orderByModels)
|
||||
{
|
||||
return Context.Queryable<T>().Where(conditionalModels).OrderBy(orderByModels).First();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Schema;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@ -842,6 +843,10 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region More api
|
||||
public string[] GetCurrentConfigIds()
|
||||
{
|
||||
return _AllClients.Select(it=>it.ConnectionConfig.ConfigId+string.Empty).ToArray();
|
||||
}
|
||||
public IContextMethods Utilities { get { return this.Context.Utilities; } set { this.Context.Utilities = value; } }
|
||||
public AopProvider Aop => this.Context.Aop;
|
||||
public ICodeFirst CodeFirst => this.Context.CodeFirst;
|
||||
|
@ -917,5 +917,9 @@ namespace SqlSugar
|
||||
{
|
||||
ScopedContext.ClearTracking();
|
||||
}
|
||||
public string[] GetCurrentConfigIds()
|
||||
{
|
||||
return ScopedContext.GetCurrentConfigIds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user