mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Update core
This commit is contained in:
parent
216b6adee6
commit
7d25c66f80
@ -21,7 +21,8 @@ namespace SqlSugar
|
||||
private bool IsDefaultValue { get; set; }
|
||||
private Func<string, bool> WhereColumnsfunc;
|
||||
private Func<string, string> FormatFileNameFunc { get; set; }
|
||||
private bool IsStringNullable {get;set;}
|
||||
private bool IsStringNullable {get;set; }
|
||||
private Func<DbColumnInfo,string,string,string> PropertyTextTemplateFunc { get; set; }
|
||||
private ISqlBuilder SqlBuilder
|
||||
{
|
||||
get
|
||||
@ -97,6 +98,11 @@ namespace SqlSugar
|
||||
this.PropertyTemplate = func(this.PropertyTemplate);
|
||||
return this;
|
||||
}
|
||||
public IDbFirst SettingPropertyTemplate(Func<DbColumnInfo, string,string,string> func)
|
||||
{
|
||||
this.PropertyTextTemplateFunc = func;
|
||||
return this;
|
||||
}
|
||||
public RazorFirst UseRazorAnalysis(string razorClassTemplate, string classNamespace = "Models")
|
||||
{
|
||||
if (razorClassTemplate == null)
|
||||
@ -264,7 +270,7 @@ namespace SqlSugar
|
||||
string PropertyDescriptionText = this.PropertyDescriptionTemplate;
|
||||
string propertyName = GetPropertyName(item);
|
||||
string propertyTypeName = GetPropertyTypeName(item);
|
||||
PropertyText = GetPropertyText(item, PropertyText);
|
||||
PropertyText =this.PropertyTextTemplateFunc == null? GetPropertyText(item, PropertyText):this.PropertyTextTemplateFunc(item,this.PropertyTemplate, propertyTypeName);
|
||||
PropertyDescriptionText = GetPropertyDescriptionText(item, PropertyDescriptionText);
|
||||
PropertyText = PropertyDescriptionText + PropertyText;
|
||||
classText = classText.Replace(DbFirstTemplate.KeyPropertyName, PropertyText + (isLast ? "" : ("\r\n" + DbFirstTemplate.KeyPropertyName)));
|
||||
@ -284,6 +290,7 @@ namespace SqlSugar
|
||||
classText = classText.Replace(DbFirstTemplate.KeyPropertyName, null);
|
||||
return classText;
|
||||
}
|
||||
|
||||
internal string GetClassString(List<DbColumnInfo> columns, ref string className)
|
||||
{
|
||||
string classText = this.ClassTemplate;
|
||||
|
@ -9,6 +9,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class FastBuilder
|
||||
{
|
||||
public virtual bool IsActionUpdateColumns { get; set; }
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public virtual string CharacterSet { get; set; }
|
||||
public virtual string UpdateSql { get; set; } = @"UPDATE TM
|
||||
|
@ -128,6 +128,7 @@ namespace SqlSugar
|
||||
this.context.CurrentConnectionConfig.IsAutoCloseConnection = false;
|
||||
DataTable dt = ToDdateTable(datas);
|
||||
IFastBuilder buider = GetBuider();
|
||||
ActionIgnoreColums(whereColumns, updateColumns, dt, buider.IsActionUpdateColumns);
|
||||
buider.Context = context;
|
||||
await buider.CreateTempAsync<T>(dt);
|
||||
await buider.ExecuteBulkCopyAsync(dt);
|
||||
@ -142,6 +143,34 @@ namespace SqlSugar
|
||||
End(datas, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ActionIgnoreColums(string[] whereColumns, string[] updateColumns, DataTable dt,bool IsActionUpdateColumns)
|
||||
{
|
||||
if (entityInfo.Columns.Where(it => it.IsIgnore == false).Count() > whereColumns.Length + updateColumns.Length &&IsActionUpdateColumns)
|
||||
{
|
||||
var ignoreColums = dt.Columns.Cast<DataColumn>()
|
||||
.Where(it => !whereColumns.Any(y => y.EqualCase(it.ColumnName)))
|
||||
.Where(it => !updateColumns.Any(y => y.EqualCase(it.ColumnName))).ToList();
|
||||
foreach (DataRow item in dt.Rows)
|
||||
{
|
||||
foreach (var col in ignoreColums)
|
||||
{
|
||||
if (item[col.ColumnName].IsNullOrEmpty())
|
||||
{
|
||||
if (col.DataType == UtilConstants.StringType)
|
||||
{
|
||||
item[col.ColumnName] = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
item[col.ColumnName] = Activator.CreateInstance(col.DataType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<int> _BulkUpdate(string tableName,DataTable dataTable, string[] whereColumns, string[] updateColumns)
|
||||
{
|
||||
var datas = new string[dataTable.Rows.Count].ToList();
|
||||
|
@ -10,6 +10,7 @@ namespace SqlSugar
|
||||
IDbFirst SettingClassTemplate(Func<string, string> func);
|
||||
IDbFirst SettingClassDescriptionTemplate(Func<string, string> func);
|
||||
IDbFirst SettingPropertyTemplate(Func<string, string> func);
|
||||
IDbFirst SettingPropertyTemplate(Func<DbColumnInfo, string,string,string> func);
|
||||
IDbFirst SettingPropertyDescriptionTemplate(Func<string, string> func);
|
||||
IDbFirst SettingConstructorTemplate(Func<string, string> func);
|
||||
IDbFirst SettingNamespaceTemplate(Func<string, string> func);
|
||||
|
@ -9,6 +9,7 @@ namespace SqlSugar
|
||||
{
|
||||
public interface IFastBuilder
|
||||
{
|
||||
bool IsActionUpdateColumns { get; set; }
|
||||
SqlSugarProvider Context { get; set; }
|
||||
string CharacterSet { get; set; }
|
||||
Task<int> UpdateByTempAsync(string tableName,string tempName,string [] updateColumns,string[] whereColumns);
|
||||
|
@ -12,6 +12,7 @@ namespace SqlSugar
|
||||
|
||||
public class SqlServerFastBuilder:FastBuilder,IFastBuilder
|
||||
{
|
||||
public override bool IsActionUpdateColumns { get; set; } = true;
|
||||
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
||||
{
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace SqlSugar
|
||||
private bool IsUpdate = false;
|
||||
public string CharacterSet { get; set; }
|
||||
private DataTable UpdateDataTable { get; set; }
|
||||
public bool IsActionUpdateColumns { get; set; }
|
||||
public SqliteFastBuilder(EntityInfo entityInfo)
|
||||
{
|
||||
this.entityInfo = entityInfo;
|
||||
|
Loading…
Reference in New Issue
Block a user