mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 增加 IInsert IgnoreInsertValueSql 方法临时忽略 InsertValueSql 设置;
This commit is contained in:
parent
598c9ee078
commit
486a05a3f7
@ -33,7 +33,7 @@ public class IdentityUser1
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[MaxLength(32)]
|
[MaxLength(32)]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
[MaxLength(64)]
|
[MaxLength(64), Column(InsertValueSql = "'defaultname'")]
|
||||||
public string Nickname { get; set; }
|
public string Nickname { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,6 +587,7 @@ namespace base_entity
|
|||||||
new IdentityUser1 { Nickname = "nickname23", Username = "username23" }
|
new IdentityUser1 { Nickname = "nickname23", Username = "username23" }
|
||||||
};
|
};
|
||||||
fsql.Insert(bulkUsers).NoneParameter().ExecuteAffrows();
|
fsql.Insert(bulkUsers).NoneParameter().ExecuteAffrows();
|
||||||
|
fsql.Insert(bulkUsers).IgnoreInsertValueSql(a => a.Nickname).NoneParameter().ExecuteAffrows();
|
||||||
bulkUsers = fsql.Select<IdentityUser1>().OrderByDescending(a => a.Id).Limit(3).ToList().ToArray();
|
bulkUsers = fsql.Select<IdentityUser1>().OrderByDescending(a => a.Id).Limit(3).ToList().ToArray();
|
||||||
bulkUsers[0].Nickname += "_bulkupdate";
|
bulkUsers[0].Nickname += "_bulkupdate";
|
||||||
bulkUsers[1].Nickname += "_bulkupdate";
|
bulkUsers[1].Nickname += "_bulkupdate";
|
||||||
|
@ -800,5 +800,14 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||||
|
<summary>
|
||||||
|
批量注入 Repository,可以参考代码自行调整
|
||||||
|
</summary>
|
||||||
|
<param name="services"></param>
|
||||||
|
<param name="globalDataFilter"></param>
|
||||||
|
<param name="assemblies"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -1650,6 +1650,14 @@
|
|||||||
<param name="columns">属性名,或者字段名</param>
|
<param name="columns">属性名,或者字段名</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSql.IInsert`1.IgnoreInsertValueSql(System.Linq.Expressions.Expression{System.Func{`0,System.Object}})">
|
||||||
|
<summary>
|
||||||
|
忽略 InsertValueSql 设置,将使用实体对象的值插入<para></para>
|
||||||
|
IgnoreInsertValueSql(a => a.Name) | IgnoreInsertValueSql(a => new{a.Name,a.Time}) | IgnoreInsertValueSql(a => new[]{"name","time"})
|
||||||
|
</summary>
|
||||||
|
<param name="columns">属性名,或者字段名</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.IInsert`1.InsertIdentity">
|
<member name="M:FreeSql.IInsert`1.InsertIdentity">
|
||||||
<summary>
|
<summary>
|
||||||
指定可插入自增字段
|
指定可插入自增字段
|
||||||
|
@ -76,6 +76,14 @@ namespace FreeSql
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IInsert<T1> IgnoreColumns(string[] columns);
|
IInsert<T1> IgnoreColumns(string[] columns);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 忽略 InsertValueSql 设置,将使用实体对象的值插入<para></para>
|
||||||
|
/// IgnoreInsertValueSql(a => a.Name) | IgnoreInsertValueSql(a => new{a.Name,a.Time}) | IgnoreInsertValueSql(a => new[]{"name","time"})
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="columns">属性名,或者字段名</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IInsert<T1> IgnoreInsertValueSql(Expression<Func<T1, object>> columns);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 指定可插入自增字段
|
/// 指定可插入自增字段
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -308,9 +308,9 @@ namespace FreeSql.Aop
|
|||||||
#region AuditValue
|
#region AuditValue
|
||||||
public class AuditValueEventArgs : EventArgs
|
public class AuditValueEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public AuditValueEventArgs(AuditValueType autoValueType, ColumnInfo column, PropertyInfo property, object value, object obj)
|
public AuditValueEventArgs(AuditValueType auditValueType, ColumnInfo column, PropertyInfo property, object value, object obj)
|
||||||
{
|
{
|
||||||
this.AuditValueType = autoValueType;
|
this.AuditValueType = auditValueType;
|
||||||
this.Column = column;
|
this.Column = column;
|
||||||
this.Property = property;
|
this.Property = property;
|
||||||
this._value = value;
|
this._value = value;
|
||||||
|
@ -20,6 +20,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
public CommonUtils _commonUtils;
|
public CommonUtils _commonUtils;
|
||||||
public CommonExpression _commonExpression;
|
public CommonExpression _commonExpression;
|
||||||
public Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
|
public Dictionary<string, bool> _ignoreInsertValueSql = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public Dictionary<string, bool> _auditValueChangedDict = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, bool> _auditValueChangedDict = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public TableInfo _table;
|
public TableInfo _table;
|
||||||
public Func<string, string> _tableRule;
|
public Func<string, string> _tableRule;
|
||||||
@ -72,6 +73,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
_source.Clear();
|
_source.Clear();
|
||||||
_sourceOld = _source;
|
_sourceOld = _source;
|
||||||
_ignore.Clear();
|
_ignore.Clear();
|
||||||
|
_ignoreInsertValueSql.Clear();
|
||||||
_auditValueChangedDict.Clear();
|
_auditValueChangedDict.Clear();
|
||||||
_params = null;
|
_params = null;
|
||||||
IgnoreCanInsert();
|
IgnoreCanInsert();
|
||||||
@ -530,6 +532,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
public IInsert<T1> IgnoreColumns(Expression<Func<T1, object>> columns) => IgnoreColumns(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
public IInsert<T1> IgnoreColumns(Expression<Func<T1, object>> columns) => IgnoreColumns(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
||||||
public IInsert<T1> InsertColumns(Expression<Func<T1, object>> columns) => InsertColumns(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
public IInsert<T1> InsertColumns(Expression<Func<T1, object>> columns) => InsertColumns(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
||||||
|
public IInsert<T1> IgnoreInsertValueSql(Expression<Func<T1, object>> columns) => IgnoreInsertValueSql(_commonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null));
|
||||||
|
|
||||||
public IInsert<T1> IgnoreColumns(string[] columns)
|
public IInsert<T1> IgnoreColumns(string[] columns)
|
||||||
{
|
{
|
||||||
@ -549,6 +552,15 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
_ignore.Add(col.Attribute.Name, true);
|
_ignore.Add(col.Attribute.Name, true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public IInsert<T1> IgnoreInsertValueSql(string[] columns)
|
||||||
|
{
|
||||||
|
var cols = columns.Distinct().ToDictionary(a => a);
|
||||||
|
_ignoreInsertValueSql.Clear();
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
if (cols.ContainsKey(col.Attribute.Name) == true || cols.ContainsKey(col.CsName) == true)
|
||||||
|
_ignoreInsertValueSql.Add(col.Attribute.Name, true);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
protected string TableRuleInvoke()
|
protected string TableRuleInvoke()
|
||||||
{
|
{
|
||||||
@ -655,7 +667,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||||
|
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
if (string.IsNullOrEmpty(col.DbInsertValue) == false)
|
if (string.IsNullOrEmpty(col.DbInsertValue) == false && _ignoreInsertValueSql.ContainsKey(col.Attribute.Name) == false)
|
||||||
sb.Append(col.DbInsertValue);
|
sb.Append(col.DbInsertValue);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ namespace FreeSql.Custom.Oracle
|
|||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||||
|
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
if (string.IsNullOrEmpty(col.DbInsertValue) == false)
|
if (string.IsNullOrEmpty(col.DbInsertValue) == false && _ignoreInsertValueSql.ContainsKey(col.Attribute.Name) == false)
|
||||||
sb.Append(col.DbInsertValue);
|
sb.Append(col.DbInsertValue);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,7 @@ namespace FreeSql.Dameng.Curd
|
|||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||||
|
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
if (string.IsNullOrEmpty(col.DbInsertValue) == false)
|
if (string.IsNullOrEmpty(col.DbInsertValue) == false && _ignoreInsertValueSql.ContainsKey(col.Attribute.Name) == false)
|
||||||
sb.Append(col.DbInsertValue);
|
sb.Append(col.DbInsertValue);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ namespace FreeSql.Odbc.Dameng
|
|||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||||
|
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
if (string.IsNullOrEmpty(col.DbInsertValue) == false)
|
if (string.IsNullOrEmpty(col.DbInsertValue) == false && _ignoreInsertValueSql.ContainsKey(col.Attribute.Name) == false)
|
||||||
sb.Append(col.DbInsertValue);
|
sb.Append(col.DbInsertValue);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ namespace FreeSql.Odbc.Oracle
|
|||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||||
|
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
if (string.IsNullOrEmpty(col.DbInsertValue) == false)
|
if (string.IsNullOrEmpty(col.DbInsertValue) == false && _ignoreInsertValueSql.ContainsKey(col.Attribute.Name) == false)
|
||||||
sb.Append(col.DbInsertValue);
|
sb.Append(col.DbInsertValue);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -80,7 +80,7 @@ namespace FreeSql.Oracle.Curd
|
|||||||
foreach (var col in cols)
|
foreach (var col in cols)
|
||||||
{
|
{
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
if (string.IsNullOrEmpty(col.DbInsertValue) == false)
|
if (string.IsNullOrEmpty(col.DbInsertValue) == false && _ignoreInsertValueSql.ContainsKey(col.Attribute.Name) == false)
|
||||||
sb.Append(col.DbInsertValue);
|
sb.Append(col.DbInsertValue);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -144,7 +144,7 @@ namespace FreeSql.Oracle.Curd
|
|||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||||
|
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
if (string.IsNullOrEmpty(col.DbInsertValue) == false)
|
if (string.IsNullOrEmpty(col.DbInsertValue) == false && _ignoreInsertValueSql.ContainsKey(col.Attribute.Name) == false)
|
||||||
sb.Append(col.DbInsertValue);
|
sb.Append(col.DbInsertValue);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user