Synchronization code

This commit is contained in:
sunkaixuan 2024-08-19 06:30:10 +08:00
parent 644adf43e2
commit 2dbc2ec207
12 changed files with 94 additions and 12 deletions

View File

@ -38,7 +38,20 @@ namespace SqlSugar
Context = result
};
}
public CommonMethodInfo EnableDiffLogEvent(object businessData = null)
{
if (Context == null)
{
return new CommonMethodInfo();
}
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var newMethod = inertable.GetType().GetMyMethod("EnableDiffLogEvent", 1, typeof(object));
var result = newMethod.Invoke(inertable, new object[] { businessData });
return new CommonMethodInfo()
{
Context = result
};
}
public CommonMethodInfo SplitTable()
{
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });

View File

@ -82,6 +82,8 @@ namespace SqlSugar
attributeType.GetProperty(nameof(SugarColumn.ExtendedAttribute)),
attributeType.GetProperty(nameof(SugarColumn.IsDisabledAlterColumn)),
attributeType.GetProperty(nameof(SugarColumn.IsOwnsOne)),
attributeType.GetProperty(nameof(SugarColumn.InsertServerTime)),
attributeType.GetProperty(nameof(SugarColumn.UpdateServerTime)),
attributeType.GetProperty(nameof(SugarColumn.QuerySql))
}
, new object[] {
@ -108,6 +110,8 @@ namespace SqlSugar
sugarTable.ExtendedAttribute,
sugarTable.IsDisabledAlterColumn,
sugarTable.IsOwnsOne,
sugarTable.InsertServerTime,
sugarTable.UpdateServerTime,
sugarTable.QuerySql
});
return attributeBuilder;

View File

@ -60,6 +60,16 @@ namespace SqlSugar
Context = result
};
}
public CommonMethodInfo EnableDiffLogEvent(object businessData = null)
{
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var newMethod = inertable.GetType().GetMyMethod("EnableDiffLogEvent", 1, typeof(object));
var result = newMethod.Invoke(inertable, new object[] { businessData });
return new CommonMethodInfo()
{
Context = result
};
}
public CommonMethodInfo IgnoreColumns(params string [] ignoreColumns)
{
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });

View File

@ -317,7 +317,7 @@ namespace SqlSugar
{
column.DbColumnName = column.PropertyName;
}
if (isMapping)
if (isMapping&&column.ForOwnsOnePropertyInfo==null)
{
columnInfo.DbColumnName = GetDbColumnName(column.PropertyName);
}

View File

@ -1500,7 +1500,21 @@ namespace SqlSugar
}
else
{
return this.Select<TResult>(this.SqlBuilder.SqlSelectAll);
if (this.QueryBuilder.IsSingle()&&this.EntityInfo?.Type?.GetCustomAttribute<SplitTableAttribute>() != null&& this.QueryBuilder?.SelectValue?.ToString()=="*")
{
var columnAarray = this.Context.EntityMaintenance.GetEntityInfo<T>().Columns;
var sql = string.Empty;
var columns= columnAarray.Where(it => typeof(TResult).GetProperties().Any(s => s.Name.EqualCase(it.PropertyName))).Where(it => it.IsIgnore == false).ToList();
if (columns.Any())
{
sql = string.Join(",", columns.Select(it => $"{SqlBuilder.GetTranslationColumnName(it.DbColumnName)} AS {SqlBuilder.GetTranslationColumnName(it.PropertyName)} "));
}
return this.Select<TResult>(sql);
}
else
{
return this.Select<TResult>(this.SqlBuilder.SqlSelectAll);
}
}
}
else
@ -1687,6 +1701,7 @@ namespace SqlSugar
//}
var unionall = this.Context._UnionAll(tableQueryables.ToArray());
unionall.QueryBuilder.Includes = this.QueryBuilder.Includes;
unionall.QueryBuilder.EntityType = typeof(T);
if (unionall.QueryBuilder.Includes?.Any()==true)
{
unionall.QueryBuilder.NoCheckInclude = true;

View File

@ -653,8 +653,12 @@ namespace SqlSugar
{
return resulut.Select<T>("unionTable.*");
}
else
else if (this.Context.CurrentConnectionConfig?.MoreSettings?.IsWithNoLockQuery==true)
{
return resulut.Select<T>(sqlBuilder.SqlSelectAll).With(SqlWith.Null);
}
else
{
return resulut.Select<T>(sqlBuilder.SqlSelectAll);
}
}

View File

@ -13,11 +13,11 @@ namespace SqlSugar
internal MethodInfo MethodInfo { get; set; }
internal object objectValue { get; set; }
public int ExecuteCommandWithOptLock(bool isThrowError = false)
public int ExecuteCommandWithOptLock(bool isThrowError = false)
{
if (Context == null) return 0;
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var result = inertable.GetType().GetMyMethod("ExecuteCommandWithOptLock",1,typeof(bool)).Invoke(inertable, new object[] { isThrowError });
var result = inertable.GetType().GetMyMethod("ExecuteCommandWithOptLock", 1, typeof(bool)).Invoke(inertable, new object[] { isThrowError });
return (int)result;
}
@ -26,13 +26,13 @@ namespace SqlSugar
if (Context == null) return 0;
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var result = inertable.GetType().GetMyMethod("ExecuteCommandWithOptLockAsync", 1, typeof(bool)).Invoke(inertable, new object[] { isThrowError });
return await(Task<int>)result;
return await (Task<int>)result;
}
public int ExecuteCommand()
{
if (Context == null) return 0;
var inertable=MethodInfo.Invoke(Context, new object[] { objectValue });
var result= inertable.GetType().GetMethod("ExecuteCommand").Invoke(inertable,new object[] { });
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var result = inertable.GetType().GetMethod("ExecuteCommand").Invoke(inertable, new object[] { });
return (int)result;
}
@ -40,9 +40,23 @@ namespace SqlSugar
{
if (Context == null) return 0;
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var result = inertable.GetType().GetMyMethod("ExecuteCommandAsync",0).Invoke(inertable, new object[] { });
var result = inertable.GetType().GetMyMethod("ExecuteCommandAsync", 0).Invoke(inertable, new object[] { });
return await (Task<int>)result;
}
public UpdateCommonMethodInfo EnableDiffLogEvent(object businessData = null)
{
if(Context == null)
{
return new UpdateCommonMethodInfo();
}
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var newMethod = inertable.GetType().GetMyMethod("EnableDiffLogEvent", 1, typeof(object));
var result = newMethod.Invoke(inertable, new object[] { businessData });
return new UpdateCommonMethodInfo()
{
Context = result
};
}
public UpdateCommonMethodInfo IgnoreColumns(params string[] ignoreColumns)
{
if (Context == null)

View File

@ -386,6 +386,10 @@ namespace SqlSugar
UpdateServerTime = column.UpdateServerTime,
IsPrimarykey=column.IsPrimarykey
};
if (column.ForOwnsOnePropertyInfo != null)
{
columnInfo.DbColumnName = column.DbColumnName;
}
if (columnInfo.PropertyType.IsEnum() && columnInfo.Value != null)
{
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)

View File

@ -134,6 +134,10 @@ namespace SqlSugar
}
var value = GetNewExpressionValue(express.Object);
var dateString2 = this.Context.DbMehtods.GetDateString(value, format);
if (IsSqlServerModel())
{
dateString2= string.Format("FORMAT({0},'{1}','en-US')", value, format);
}
if (dateString2 == null)
{
var dateString = GeDateFormat(format, value);

View File

@ -20,6 +20,10 @@ namespace SqlSugar
}
else if (IsOracle() || IsPg())
{
if (this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.SqlServer)
{
return string.Format("FORMAT({0},'{1}','en-US')", value, formatString);
}
if (!(formatString?.Contains("24") == true))
{
formatString = formatString.Replace("HH", "hh24");

View File

@ -1,4 +1,4 @@
using System;
 using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -786,6 +786,10 @@ namespace SqlSugar
if (model.Args.Count > 1)
{
var dateString2 = this.Context.DbMehtods.GetDateString(model.Args.First().MemberName.ObjToString(), model.Args.Last().MemberValue.ObjToString());
if (IsSqlServerModel())
{
return string.Format("FORMAT({0},'{1}','en-US')", model.Args.First().MemberName.ObjToString(), model.Args.Last().MemberValue.ObjToString());
}
if (dateString2 != null) return dateString2;
return GeDateFormat(model.Args.Last().MemberValue.ObjToString(), model.Args.First().MemberName.ObjToString());
}
@ -999,6 +1003,11 @@ namespace SqlSugar
return null;
}
private bool IsSqlServerModel()
{
return this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.SqlServer;
}
private string GetLike(string result, bool iLike)
{
if (iLike)

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
@ -171,7 +172,7 @@ namespace SqlSugar
{
day = group3;
}
return Convert.ToDateTime($"{year}-{month}-{day}");
return Convert.ToDateTime($"{year}-{month}-{day}",CultureInfo.InvariantCulture);
}
private string PadLeft2(string str)