mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-17 01:46:18 +08:00
Update Insertable
This commit is contained in:
parent
bf40f8af5f
commit
e12bd7eb06
@ -30,7 +30,7 @@ namespace OrmTest.Demo
|
|||||||
|
|
||||||
//Only insert Name and SchoolId
|
//Only insert Name and SchoolId
|
||||||
var t4 = db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.SchoolId }).ExecuteReturnIdentity();
|
var t4 = db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.SchoolId }).ExecuteReturnIdentity();
|
||||||
var t4_1 = db.Insertable(insertObj).InsertColumns(it => it=="Name"||it== "SchoolId").ExecuteReturnIdentity();
|
var t4_1 = db.Insertable(insertObj).InsertColumns("Name","SchoolId").ExecuteReturnIdentity();
|
||||||
|
|
||||||
|
|
||||||
//Ignore TestId
|
//Ignore TestId
|
||||||
@ -38,7 +38,7 @@ namespace OrmTest.Demo
|
|||||||
|
|
||||||
|
|
||||||
//Ignore TestId
|
//Ignore TestId
|
||||||
var t6 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReturnIdentity();
|
var t6 = db.Insertable(insertObj).IgnoreColumns( "Name","TestId").ExecuteReturnIdentity();
|
||||||
|
|
||||||
|
|
||||||
//Use Lock
|
//Use Lock
|
||||||
@ -46,7 +46,7 @@ namespace OrmTest.Demo
|
|||||||
|
|
||||||
|
|
||||||
var insertObj2 = new Student() { Name = null, CreateTime = Convert.ToDateTime("2010-1-1") };
|
var insertObj2 = new Student() { Name = null, CreateTime = Convert.ToDateTime("2010-1-1") };
|
||||||
var t9 = db.Insertable(insertObj2).Where(true/* Is insert null */, false/*off identity*/).ExecuteCommand();
|
var t9 = db.Insertable(insertObj2).IgnoreColumns(ignoreNullColumn:true).ExecuteCommand();
|
||||||
|
|
||||||
//Insert List<T>
|
//Insert List<T>
|
||||||
var insertObjs = new List<Student>();
|
var insertObjs = new List<Student>();
|
||||||
|
@ -204,9 +204,11 @@ namespace SqlSugar
|
|||||||
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Any(ig => ig.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))).ToList();
|
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Any(ig => ig.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))).ToList();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public IInsertable<T> IgnoreColumns(Func<string, bool> ignoreColumMethod)
|
public IInsertable<T> IgnoreColumns(params string[] columns)
|
||||||
{
|
{
|
||||||
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !ignoreColumMethod(it.PropertyName)).ToList();
|
if (columns == null)
|
||||||
|
columns = new string[] { };
|
||||||
|
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !columns.Any(ig => ig.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase))).ToList();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,25 +225,17 @@ namespace SqlSugar
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IInsertable<T> InsertColumns(Func<string, bool> insertColumMethod)
|
|
||||||
{
|
|
||||||
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => insertColumMethod(it.PropertyName)).ToList();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IInsertable<T> With(string lockString)
|
public IInsertable<T> With(string lockString)
|
||||||
{
|
{
|
||||||
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
||||||
this.InsertBuilder.TableWithString = lockString;
|
this.InsertBuilder.TableWithString = lockString;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public IInsertable<T> IgnoreColumns(bool ignoreNullColumn, bool isOffIdentity = false) {
|
||||||
public IInsertable<T> Where(bool isNoInsertNull, bool isOffIdentity = false)
|
|
||||||
{
|
|
||||||
this.IsOffIdentity = isOffIdentity;
|
this.IsOffIdentity = isOffIdentity;
|
||||||
if (this.InsertBuilder.LambdaExpressions == null)
|
if (this.InsertBuilder.LambdaExpressions == null)
|
||||||
this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
|
this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
|
||||||
this.InsertBuilder.IsNoInsertNull = isNoInsertNull;
|
this.InsertBuilder.IsNoInsertNull = ignoreNullColumn;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,5 +562,25 @@ namespace SqlSugar
|
|||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Obsolete
|
||||||
|
[Obsolete]
|
||||||
|
public IInsertable<T> InsertColumns(Func<string, bool> insertColumMethod)
|
||||||
|
{
|
||||||
|
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => insertColumMethod(it.PropertyName)).ToList();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
[Obsolete]
|
||||||
|
public IInsertable<T> IgnoreColumns(Func<string, bool> ignoreColumMethod)
|
||||||
|
{
|
||||||
|
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !ignoreColumMethod(it.PropertyName)).ToList();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
[Obsolete]
|
||||||
|
public IInsertable<T> Where(bool ignoreNullColumn, bool isOffIdentity = false)
|
||||||
|
{
|
||||||
|
return IgnoreColumns(ignoreNullColumn, isOffIdentity);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,26 @@ namespace SqlSugar
|
|||||||
IInsertable<T> AS(string tableName);
|
IInsertable<T> AS(string tableName);
|
||||||
IInsertable<T> With(string lockString);
|
IInsertable<T> With(string lockString);
|
||||||
IInsertable<T> InsertColumns(Expression<Func<T, object>> columns);
|
IInsertable<T> InsertColumns(Expression<Func<T, object>> columns);
|
||||||
IInsertable<T> InsertColumns(string[] columns);
|
IInsertable<T> InsertColumns(params string[] columns);
|
||||||
IInsertable<T> InsertColumns(Func<string, bool> insertColumMethod);
|
|
||||||
IInsertable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
IInsertable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||||
IInsertable<T> IgnoreColumns(Func<string,bool> ignoreColumMethod);
|
IInsertable<T> IgnoreColumns(params string[]columns);
|
||||||
IInsertable<T> Where(bool isInsertNull, bool isOffIdentity = false);
|
IInsertable<T> IgnoreColumns(bool ignoreNullColumn, bool isOffIdentity = false);
|
||||||
|
|
||||||
|
|
||||||
IInsertable<T> EnableDiffLogEvent(object businessData = null);
|
IInsertable<T> EnableDiffLogEvent(object businessData = null);
|
||||||
IInsertable<T> RemoveDataCache();
|
IInsertable<T> RemoveDataCache();
|
||||||
KeyValuePair<string, List<SugarParameter>> ToSql();
|
KeyValuePair<string, List<SugarParameter>> ToSql();
|
||||||
void AddQueue();
|
void AddQueue();
|
||||||
|
|
||||||
|
#region Obsolete
|
||||||
|
[Obsolete("use IgnoreColumns(string[] columns")]
|
||||||
|
|
||||||
|
IInsertable<T> IgnoreColumns(Func<string, bool> ignoreColumMethod);
|
||||||
|
[Obsolete("use InsertColumns(string[] columns")]
|
||||||
|
IInsertable<T> InsertColumns(Func<string, bool> insertColumMethod);
|
||||||
|
[Obsolete("use IgnoreColumns(bool isNoInsertNull, bool isOffIdentity = false)")]
|
||||||
|
IInsertable<T> Where(bool ignoreNullColumn, bool isOffIdentity = false);
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user