Browse Source

Update IInsertable

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
2348bbff3e
  1. 3
      SqlServerTest/Demos/Insert.cs
  2. 17
      SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  3. 1
      SqlSugar/Interface/Insertable.cs

3
SqlServerTest/Demos/Insert.cs

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

17
SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

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

1
SqlSugar/Interface/Insertable.cs

@ -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…
Cancel
Save