mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-25 04:02:51 +08:00
33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using FreeSql.Internal;
|
|
using System.Linq;
|
|
|
|
namespace FreeSql.Odbc.PostgreSQL
|
|
{
|
|
|
|
class OdbcPostgreSQLInsertOrUpdate<T1> : Internal.CommonProvider.InsertOrUpdateProvider<T1> where T1 : class
|
|
{
|
|
public OdbcPostgreSQLInsertOrUpdate(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 OdbcPostgreSQLOnConflictDoUpdate<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;
|
|
}
|
|
}
|
|
} |