mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Support mysql ignore insert
This commit is contained in:
parent
de0446270a
commit
329a684ae2
@ -473,6 +473,12 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsertable<T> MySqlIgnore()
|
||||
{
|
||||
this.InsertBuilder.MySqlIgnore = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsertable<T> InsertColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
if (columns == null) return this;
|
||||
|
@ -129,6 +129,9 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MySqlIgnore { get; internal set; }
|
||||
|
||||
public virtual ExpressionResult GetExpressionValue(Expression expression, ResolveExpressType resolveType)
|
||||
{
|
||||
ILambdaExpressions resolveExpress = this.LambdaExpressions;
|
||||
|
@ -54,6 +54,6 @@ namespace SqlSugar
|
||||
SplitInsertable<T> SplitTable();
|
||||
SplitInsertable<T> SplitTable(SplitType splitType);
|
||||
void AddQueue();
|
||||
|
||||
IInsertable<T> MySqlIgnore();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@ -127,7 +128,9 @@ namespace SqlSugar
|
||||
{
|
||||
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it =>base.GetDbColumn(it, Builder.SqlParameterKeyWord + it.DbColumnName)));
|
||||
ActionMinDate();
|
||||
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
|
||||
var result= string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
|
||||
result = GetMySqlIgnore(result);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -140,7 +143,7 @@ namespace SqlSugar
|
||||
foreach (var item in groupList)
|
||||
{
|
||||
batchInsetrSql.Append("(");
|
||||
insertColumns = string.Join(",", item.Select(it =>base.GetDbColumn(it, FormatValue(it.Value,it.PropertyName))));
|
||||
insertColumns = string.Join(",", item.Select(it => base.GetDbColumn(it, FormatValue(it.Value, it.PropertyName))));
|
||||
batchInsetrSql.Append(insertColumns);
|
||||
if (groupList.Last() == item)
|
||||
{
|
||||
@ -151,11 +154,22 @@ namespace SqlSugar
|
||||
batchInsetrSql.Append("), ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
batchInsetrSql.AppendLine(";select @@IDENTITY");
|
||||
var result = batchInsetrSql.ToString();
|
||||
result = GetMySqlIgnore(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetMySqlIgnore(string result)
|
||||
{
|
||||
if (this.MySqlIgnore)
|
||||
{
|
||||
result = result.Replace("INSERT INTO", " INSERT IGNORE INTO");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user