mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 增加 IInsertOrUpdate.SetSource(sql) 重载方法;
This commit is contained in:
@ -3727,6 +3727,13 @@
|
||||
实体对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.ObjectAuditBreak">
|
||||
<summary>
|
||||
中断实体对象审计<para></para>
|
||||
false: 每个实体对象的属性都会审计(默认)<para></para>
|
||||
true: 每个实体对象只审计一次
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditDataReaderEventArgs.DataReader">
|
||||
<summary>
|
||||
ADO.NET 数据流读取对象
|
||||
|
@ -46,6 +46,8 @@ namespace FreeSql
|
||||
/// <returns></returns>
|
||||
IInsertOrUpdate<T1> SetSource(IEnumerable<T1> source, Expression<Func<T1, object>> tempPrimarys = null);
|
||||
|
||||
IInsertOrUpdate<T1> SetSource(string sql, Expression<Func<T1, object>> tempPrimarys = null);
|
||||
|
||||
/// <summary>
|
||||
/// 当记录存在时,什么都不做<para></para>
|
||||
/// 换句话:只有记录不存在时才插入
|
||||
|
@ -494,7 +494,7 @@ namespace FreeSql.Internal
|
||||
if (parent.Childs.Any() == false) throw new Exception(CoreStrings.Mapping_Exception_HasNo_SamePropertyName(newExp.Type.Name));
|
||||
return true;
|
||||
}
|
||||
parent.DbField = $"({ExpressionLambdaToSql(exp, getTSC())})";
|
||||
parent.DbField = ExpressionLambdaToSql(exp, getTSC()); //解决 new { a = id + 1 } 翻译后 ((id+1)) 问题
|
||||
field.Append(", ").Append(parent.DbField);
|
||||
LocalSetFieldAlias(ref index, false);
|
||||
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
||||
|
@ -36,6 +36,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public abstract partial class InsertOrUpdateProvider<T1> : InsertOrUpdateProvider, IInsertOrUpdate<T1> where T1 : class
|
||||
{
|
||||
public List<T1> _source = new List<T1>();
|
||||
public string _sourceSql = null;
|
||||
|
||||
public InsertOrUpdateProvider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||
{
|
||||
@ -53,6 +54,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
protected void ClearData()
|
||||
{
|
||||
_source.Clear();
|
||||
_sourceSql = null;
|
||||
_auditValueChangedDict.Clear();
|
||||
}
|
||||
|
||||
@ -119,6 +121,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public IInsertOrUpdate<T1> SetSource(IEnumerable<T1> source, Expression<Func<T1, object>> tempPrimarys = null)
|
||||
{
|
||||
if (source == null || source.Any() == false) return this;
|
||||
_sourceSql = null;
|
||||
UpdateProvider<T1>.GetDictionaryTableInfo(source, _orm, ref _table);
|
||||
AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
|
||||
_source.AddRange(source.Where(a => a != null));
|
||||
@ -130,6 +133,19 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public virtual IInsertOrUpdate<T1> SetSource(string sql, Expression<Func<T1, object>> tempPrimarys = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sql)) return this;
|
||||
_source.Clear();
|
||||
_sourceSql = sql;
|
||||
|
||||
if (tempPrimarys != null)
|
||||
{
|
||||
var cols = _commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, tempPrimarys?.Body, false, null).Distinct().ToDictionary(a => a);
|
||||
_tempPrimarys = cols.Keys.Select(a => _table.Columns.TryGetValue(a, out var col) ? col : null).ToArray().Where(a => a != null).ToArray();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsertOrUpdate<T1> IfExistsDoNothing()
|
||||
{
|
||||
@ -184,6 +200,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
public void WriteSourceSelectUnionAll(List<T1> source, StringBuilder sb, List<DbParameter> dbParams)
|
||||
{
|
||||
if (_sourceSql != null)
|
||||
{
|
||||
sb.Append(_sourceSql).Append("\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
var didx = 0;
|
||||
foreach (var d in source)
|
||||
{
|
||||
|
Reference in New Issue
Block a user