mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 补充 fsql.InsertOrUpdate IfExistsDoNothing 数据存在时不做任何事(不更新) #330 #316;
This commit is contained in:
@ -1151,6 +1151,13 @@
|
||||
<param name="source">实体集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IInsertOrUpdate`1.IfExistsDoNothing">
|
||||
<summary>
|
||||
当记录存在时,什么都不做<para></para>
|
||||
换句话:只有记录不存在时才插入
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IInsertOrUpdate`1.AsTable(System.Func{System.String,System.String})">
|
||||
<summary>
|
||||
设置表名规则,可用于分库/分表,参数1:默认表名;返回值:新表名;
|
||||
@ -3929,14 +3936,17 @@
|
||||
</member>
|
||||
<member name="M:IFreeSql.InsertOrUpdate``1">
|
||||
<summary>
|
||||
插入或更新数据<para></para>
|
||||
MySql: on duplicate key update<para></para>
|
||||
PostgreSQL: on conflict do update<para></para>
|
||||
SqlServer: merge into<para></para>
|
||||
Oracle: merge into<para></para>
|
||||
插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
||||
MySql 5.6+: on duplicate key update<para></para>
|
||||
PostgreSQL 9.4+: on conflict do update<para></para>
|
||||
SqlServer 2008+: merge into<para></para>
|
||||
Oracle 11+: merge into<para></para>
|
||||
Sqlite: replace into<para></para>
|
||||
Dameng: merge into<para></para>
|
||||
注意:还可以使用 FreeSql.Repository 的 InsertOrUpdate 方法
|
||||
达梦: merge into<para></para>
|
||||
人大金仓:on conflict do update<para></para>
|
||||
神通:merge into<para></para>
|
||||
MsAccess:不支持<para></para>
|
||||
注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
|
@ -35,6 +35,13 @@ namespace FreeSql
|
||||
/// <returns></returns>
|
||||
IInsertOrUpdate<T1> SetSource(IEnumerable<T1> source);
|
||||
|
||||
/// <summary>
|
||||
/// 当记录存在时,什么都不做<para></para>
|
||||
/// 换句话:只有记录不存在时才插入
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IInsertOrUpdate<T1> IfExistsDoNothing();
|
||||
|
||||
/// <summary>
|
||||
/// 设置表名规则,可用于分库/分表,参数1:默认表名;返回值:新表名;
|
||||
/// </summary>
|
||||
|
@ -45,14 +45,17 @@ public interface IFreeSql : IDisposable
|
||||
IInsert<T1> Insert<T1>(IEnumerable<T1> source) where T1 : class;
|
||||
|
||||
/// <summary>
|
||||
/// 插入或更新数据<para></para>
|
||||
/// MySql: on duplicate key update<para></para>
|
||||
/// PostgreSQL: on conflict do update<para></para>
|
||||
/// SqlServer: merge into<para></para>
|
||||
/// Oracle: merge into<para></para>
|
||||
/// 插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
||||
/// MySql 5.6+: on duplicate key update<para></para>
|
||||
/// PostgreSQL 9.4+: on conflict do update<para></para>
|
||||
/// SqlServer 2008+: merge into<para></para>
|
||||
/// Oracle 11+: merge into<para></para>
|
||||
/// Sqlite: replace into<para></para>
|
||||
/// Dameng: merge into<para></para>
|
||||
/// 注意:还可以使用 FreeSql.Repository 的 InsertOrUpdate 方法
|
||||
/// 达梦: merge into<para></para>
|
||||
/// 人大金仓:on conflict do update<para></para>
|
||||
/// 神通:merge into<para></para>
|
||||
/// MsAccess:不支持<para></para>
|
||||
/// 注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
||||
/// </summary>
|
||||
/// <typeparam name="T1"></typeparam>
|
||||
/// <returns></returns>
|
||||
|
@ -19,6 +19,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
protected CommonUtils _commonUtils;
|
||||
protected CommonExpression _commonExpression;
|
||||
protected List<T1> _source = new List<T1>();
|
||||
protected bool _doNothing = false;
|
||||
protected Dictionary<string, bool> _auditValueChangedDict = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
||||
protected TableInfo _table;
|
||||
protected Func<string, string> _tableRule;
|
||||
@ -106,6 +107,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsertOrUpdate<T1> IfExistsDoNothing()
|
||||
{
|
||||
_doNothing = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected string TableRuleInvoke()
|
||||
{
|
||||
if (_tableRule == null) return _table.DbName;
|
||||
|
@ -494,7 +494,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
public virtual string ToSql() => ToSqlValuesOrSelectUnionAll(true);
|
||||
|
||||
public string ToSqlValuesOrSelectUnionAll(bool isValues = true)
|
||||
public string ToSqlValuesOrSelectUnionAll(bool isValues = true) => ToSqlValuesOrSelectUnionAllExtension101(isValues, null);
|
||||
public string ToSqlValuesOrSelectUnionAllExtension101(bool isValues, Action<object, int, StringBuilder> onrow)
|
||||
{
|
||||
if (_source == null || _source.Any() == false) return null;
|
||||
var sb = new StringBuilder();
|
||||
@ -541,6 +542,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
++colidx2;
|
||||
}
|
||||
if (isValues) sb.Append(")");
|
||||
onrow?.Invoke(d, didx, sb);
|
||||
++didx;
|
||||
}
|
||||
if (_noneParameter && specialParams.Any())
|
||||
|
Reference in New Issue
Block a user