mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 05:13:27 +08:00
Update IInsertable
This commit is contained in:
parent
532c0259a6
commit
2348bbff3e
@ -24,8 +24,9 @@ namespace OrmTest.Demo
|
||||
var t3 = db.Insertable(insertObj).ExecuteReutrnIdentity();
|
||||
|
||||
|
||||
//Only insert Name
|
||||
//Only insert Name and SchoolId
|
||||
var t4 = db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.SchoolId }).ExecuteReutrnIdentity();
|
||||
var t4_1 = db.Insertable(insertObj).InsertColumns(it => it=="Name"||it== "SchoolId").ExecuteReutrnIdentity();
|
||||
|
||||
|
||||
//Ignore TestId
|
||||
|
@ -51,7 +51,7 @@ namespace SqlSugar
|
||||
PreToSql();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return Ado.GetInt(sql, InsertBuilder.Parameters==null?null:InsertBuilder.Parameters.ToArray());
|
||||
return Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -84,6 +84,12 @@ namespace SqlSugar
|
||||
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)
|
||||
{
|
||||
this.InsertBuilder.TableWithString = lockString;
|
||||
@ -132,8 +138,9 @@ namespace SqlSugar
|
||||
foreach (var item in this.InsertBuilder.DbColumnInfoList)
|
||||
{
|
||||
if (this.InsertBuilder.Parameters == null) this.InsertBuilder.Parameters = new List<SugarParameter>();
|
||||
var paramters = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value,item.PropertyType);
|
||||
if (InsertBuilder.IsInsertNull && paramters.Value == null) {
|
||||
var paramters = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, item.PropertyType);
|
||||
if (InsertBuilder.IsInsertNull && paramters.Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
this.InsertBuilder.Parameters.Add(paramters);
|
||||
@ -152,10 +159,10 @@ namespace SqlSugar
|
||||
{
|
||||
var columnInfo = new DbColumnInfo()
|
||||
{
|
||||
Value = column.PropertyInfo.GetValue(item,null),
|
||||
Value = column.PropertyInfo.GetValue(item, null),
|
||||
DbColumnName = GetDbColumnName(column.PropertyName),
|
||||
PropertyName = column.PropertyName,
|
||||
PropertyType=PubMethod.GetUnderType(column.PropertyInfo),
|
||||
PropertyType = PubMethod.GetUnderType(column.PropertyInfo),
|
||||
TableId = i
|
||||
};
|
||||
insertItem.Add(columnInfo);
|
||||
|
@ -14,6 +14,7 @@ namespace SqlSugar
|
||||
IInsertable<T> AS(string tableName);
|
||||
IInsertable<T> With(string lockString);
|
||||
IInsertable<T> InsertColumns(Expression<Func<T, object>> columns);
|
||||
IInsertable<T> InsertColumns(Func<string, bool> insertColumMethod);
|
||||
IInsertable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||
IInsertable<T> IgnoreColumns(Func<string,bool> ignoreColumMethod);
|
||||
IInsertable<T> Where(bool isInsertNull, bool isOffIdentity = false);
|
||||
|
Loading…
Reference in New Issue
Block a user