mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 增加 IFreeSql.InsertOrUpdate 方法 #316
This commit is contained in:
@ -1,14 +1,11 @@
|
||||
using FreeSql.Aop;
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.PostgreSQL.Curd
|
||||
|
@ -0,0 +1,33 @@
|
||||
using FreeSql.Internal;
|
||||
using System.Linq;
|
||||
|
||||
namespace FreeSql.PostgreSQL.Curd
|
||||
{
|
||||
|
||||
class PostgreSQLInsertOrUpdate<T1> : Internal.CommonProvider.InsertOrUpdateProvider<T1> where T1 : class
|
||||
{
|
||||
public PostgreSQLInsertOrUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||
: base(orm, commonUtils, commonExpression)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToSql()
|
||||
{
|
||||
if (_source?.Any() != true) return null;
|
||||
|
||||
var insert = _orm.Insert<T1>()
|
||||
.AsTable(_tableRule).AsType(_table.Type)
|
||||
.WithConnection(_connection)
|
||||
.WithTransaction(_transaction)
|
||||
.NoneParameter(true) as Internal.CommonProvider.InsertProvider<T1>;
|
||||
insert._source = _source;
|
||||
var ocdu = new OnConflictDoUpdate<T1>(insert);
|
||||
ocdu.IgnoreColumns(_table.Columns.Values.Where(a => a.Attribute.CanUpdate == false).Select(a => a.Attribute.Name).ToArray());
|
||||
if (_table.Columns.Values.Where(a => a.Attribute.IsPrimary == false && a.Attribute.CanUpdate == true).Any() == false)
|
||||
ocdu.DoNothing();
|
||||
var sql = ocdu.ToSql();
|
||||
_params = insert._params;
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user