Update IInsertable

This commit is contained in:
sunkaixuan
2017-06-04 12:13:21 +08:00
parent 532c0259a6
commit 2348bbff3e
3 changed files with 15 additions and 6 deletions

View File

@@ -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

View File

@@ -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;
@@ -133,7 +139,8 @@ namespace SqlSugar
{
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) {
if (InsertBuilder.IsInsertNull && paramters.Value == null)
{
continue;
}
this.InsertBuilder.Parameters.Add(paramters);

View File

@@ -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);