Remove Insert null validation

This commit is contained in:
sunkaixuan 2019-04-20 20:48:22 +08:00
parent 9fedcac47d
commit c0b6d6e9f1
2 changed files with 21 additions and 1 deletions

View File

@ -40,6 +40,10 @@ namespace SqlSugar
}
public virtual int ExecuteCommand()
{
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
{
return 0;
}
if (InsertBuilder.DbColumnInfoList.HasValue())
{
var pks = GetPrimaryKeys();
@ -76,6 +80,10 @@ namespace SqlSugar
}
public virtual int ExecuteReturnIdentity()
{
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
{
return 0;
}
InsertBuilder.IsReturnIdentity = true;
PreToSql();
AutoRemoveDataCache();
@ -88,6 +96,10 @@ namespace SqlSugar
}
public virtual long ExecuteReturnBigIdentity()
{
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
{
return 0;
}
InsertBuilder.IsReturnIdentity = true;
PreToSql();
AutoRemoveDataCache();
@ -353,6 +365,10 @@ namespace SqlSugar
}
private void SetInsertItemByEntity(int i, T item, List<DbColumnInfo> insertItem)
{
if (item == null)
{
return;
}
foreach (var column in EntityInfo.Columns)
{
if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue;

View File

@ -450,7 +450,11 @@ namespace SqlSugar
}
public virtual IInsertable<T> Insertable<T>(List<T> insertObjs) where T : class, new()
{
Check.ArgumentNullException(insertObjs, "Insertable.insertObjs can't be null");
if (insertObjs == null|| insertObjs.IsNullOrEmpty())
{
insertObjs = new List<T>();
insertObjs.Add(default(T));
}
return this.Context.Insertable(insertObjs.ToArray());
}
public virtual IInsertable<T> Insertable<T>(T insertObj) where T : class, new()