Update Core

This commit is contained in:
sunkaixuan 2022-03-28 21:53:15 +08:00
parent e58b8a60c2
commit c400ff6ea2
9 changed files with 54 additions and 9 deletions

View File

@ -1434,6 +1434,7 @@ namespace SqlSugar
this.Connection = this.MasterConnection;
this.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnectionString;
}
this.Context.SugarActionType = SugarActionType.UnKnown;
}
private bool IsRead(string sql)

View File

@ -31,6 +31,7 @@ namespace SqlSugar
public MappingColumnList MappingColumns { get; set; }
public IgnoreColumnList IgnoreColumns { get; set; }
public IgnoreColumnList IgnoreInsertColumns { get; set; }
public SugarActionType SugarActionType { get; set; } = SugarActionType.UnKnown;
public ConfigQuery ConfigQuery {
get
{
@ -258,6 +259,7 @@ namespace SqlSugar
}
protected ISugarQueryable<T> CreateQueryable<T>(ISugarQueryable<T> result)
{
this.SugarActionType = SugarActionType.Query;
Check.Exception(typeof(T).IsClass() == false || typeof(T).GetConstructors().Length == 0, "Queryable<{0}> Error ,{0} is invalid , need is a class,and can new().", typeof(T).Name);
var sqlBuilder = InstanceFactory.GetSqlbuilder(CurrentConnectionConfig);
result.Context = this.Context;
@ -272,6 +274,7 @@ namespace SqlSugar
}
protected InsertableProvider<T> CreateInsertable<T>(T[] insertObjs) where T : class, new()
{
this.SugarActionType = SugarActionType.Insert;
var result = InstanceFactory.GetInsertableProvider<T>(this.CurrentConnectionConfig);
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.CurrentConnectionConfig); ;
result.Context = this;
@ -287,6 +290,7 @@ namespace SqlSugar
}
protected DeleteableProvider<T> CreateDeleteable<T>() where T : class, new()
{
this.SugarActionType = SugarActionType.Delete;
var result = InstanceFactory.GetDeleteableProvider<T>(this.CurrentConnectionConfig);
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.CurrentConnectionConfig); ;
result.Context = this;
@ -299,6 +303,7 @@ namespace SqlSugar
}
protected UpdateableProvider<T> CreateUpdateable<T>(T[] UpdateObjs) where T : class, new()
{
this.SugarActionType = SugarActionType.Update;
var result = InstanceFactory.GetUpdateableProvider<T>(this.CurrentConnectionConfig);
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.CurrentConnectionConfig); ;
result.Context = this;
@ -315,6 +320,7 @@ namespace SqlSugar
protected void CreateQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable)
{
this.SugarActionType = SugarActionType.Query;
this.CreateQueryable<T>(queryable);
string shortName = string.Empty;
List<SugarParameter> paramters = new List<SugarParameter>();
@ -328,6 +334,7 @@ namespace SqlSugar
}
protected void CreateEasyQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable)
{
this.SugarActionType = SugarActionType.Query;
this.CreateQueryable<T>(queryable);
string shortName = string.Empty;
queryable.SqlBuilder.QueryBuilder.EasyJoinInfos = this.GetEasyJoinInfo(joinExpression, ref shortName, queryable.SqlBuilder, types);

View File

@ -1199,7 +1199,8 @@ namespace SqlSugar
}
#endregion
#region
#region Fastest
public IFastest<T> Fastest<T>() where T:class,new()
{
return new FastestProvider<T>(this);

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public enum SugarActionType
{
Insert=0,
Update=1,
Delete=2,
Query=3,
UnKnown = -1
}
}

View File

@ -31,7 +31,7 @@ namespace SqlSugar
EntityMaintenance EntityMaintenance { get; set; }
QueryFilterProvider QueryFilter { get; set; }
IContextMethods Utilities { get; set; }
SugarActionType SugarActionType { get; set; }
#region Deleteable
IDeleteable<T> Deleteable<T>() where T : class, new();

View File

@ -164,8 +164,16 @@ namespace SqlSugar
}
else if (parameter.DbType == System.Data.DbType.DateTime)
{
sqlParameter.Value = parameter.Value;
sqlParameter.DbType = System.Data.DbType.Date;
if (this.Context.SugarActionType == SugarActionType.Insert)
{
sqlParameter.Value = parameter.Value;
sqlParameter.DbType = System.Data.DbType.DateTime;
}
else
{
sqlParameter.Value = parameter.Value;
sqlParameter.DbType = System.Data.DbType.Date;
}
}
else if (parameter.DbType == System.Data.DbType.AnsiStringFixedLength)
{

View File

@ -33,10 +33,10 @@ namespace SqlSugar
private string GetOracleUpdateColums(DbColumnInfo m)
{
return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(), FormatValue(m.Value,m.IsPrimarykey));
return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(), FormatValue(m.Value,m.IsPrimarykey,m.PropertyName));
}
public object FormatValue(object value,bool isPrimaryKey)
int i = 0;
public object FormatValue(object value,bool isPrimaryKey,string name)
{
if (value == null)
{
@ -87,7 +87,17 @@ namespace SqlSugar
}
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{
return N + "'" + value.ToString().ToSqlFilter() + "'";
if (value.ToString().Length > 2000)
{
++i;
var parameterName = this.Builder.SqlParameterKeyWord + name + i;
this.Parameters.Add(new SugarParameter(parameterName, value));
return parameterName;
}
else
{
return N + "'" + value.ToString().ToSqlFilter() + "'";
}
}
else
{

View File

@ -49,6 +49,7 @@ namespace SqlSugar
#endregion
#region Global variable
public SugarActionType SugarActionType { get { return this.Context.SugarActionType; }set { this.Context.SugarActionType = value; } }
public SqlSugarProvider Context { get { return GetContext(); } }
public bool IsSystemTablesConfig => this.Context.IsSystemTablesConfig;
public ConnectionConfig CurrentConnectionConfig { get { return _CurrentConnectionConfig; } set { _CurrentConnectionConfig = value; } }

View File

@ -35,7 +35,7 @@ namespace SqlSugar
this._configAction = configAction;
}
public SqlSugarClient ScopedContext{ get{ return GetContext();}}
public SugarActionType SugarActionType { get => ScopedContext.SugarActionType;set=> ScopedContext.SugarActionType=value; }
public MappingTableList MappingTables { get => ScopedContext.MappingTables; set => ScopedContext.MappingTables = value; }
public MappingColumnList MappingColumns { get => ScopedContext.MappingColumns; set => ScopedContext.MappingColumns=value; }
public IgnoreColumnList IgnoreColumns { get => ScopedContext.IgnoreColumns; set => ScopedContext.IgnoreColumns=value; }