mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 IInsert.InsertIdentity 可插入自增属性;
This commit is contained in:
parent
5fc603a18b
commit
9b80f8cd53
@ -322,6 +322,7 @@ namespace FreeSql.Tests
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
//g.sqlite.Aop.ParseExpression += parseExp;
|
||||
|
||||
var sqddddl = g.sqlite.Select<TaskBuild>().ToSql(t => t.OptionsEntity04 == "1".TryTo<int>());
|
||||
|
@ -649,6 +649,12 @@
|
||||
<param name="columns">lambda选择列</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IInsert`1.InsertIdentity">
|
||||
<summary>
|
||||
指定可插入自增字段
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IInsert`1.NoneParameter">
|
||||
<summary>
|
||||
不使用参数化,可通过 IFreeSql.CodeFirst.IsNotCommandParameter 全局性设置
|
||||
|
@ -54,6 +54,12 @@ namespace FreeSql
|
||||
/// <returns></returns>
|
||||
IInsert<T1> IgnoreColumns(Expression<Func<T1, object>> columns);
|
||||
|
||||
/// <summary>
|
||||
/// 指定可插入自增字段
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IInsert<T1> InsertIdentity();
|
||||
|
||||
/// <summary>
|
||||
/// 不使用参数化,可通过 IFreeSql.CodeFirst.IsNotCommandParameter 全局性设置
|
||||
/// </summary>
|
||||
|
@ -21,7 +21,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
protected Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
||||
protected TableInfo _table;
|
||||
protected Func<string, string> _tableRule;
|
||||
protected bool _noneParameter;
|
||||
protected bool _noneParameter, _insertIdentity;
|
||||
protected DbParameter[] _params;
|
||||
protected DbTransaction _transaction;
|
||||
protected DbConnection _connection;
|
||||
@ -38,6 +38,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
protected void ClearData()
|
||||
{
|
||||
_insertIdentity = false;
|
||||
_source.Clear();
|
||||
_ignore.Clear();
|
||||
_params = null;
|
||||
@ -56,6 +57,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsert<T1> InsertIdentity()
|
||||
{
|
||||
_insertIdentity = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IInsert<T1> NoneParameter()
|
||||
{
|
||||
_noneParameter = true;
|
||||
@ -526,8 +533,10 @@ namespace FreeSql.Internal.CommonProvider
|
||||
sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append("(");
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false)
|
||||
{
|
||||
if (_ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||
if (col.Attribute.IsIdentity && _insertIdentity == false) continue;
|
||||
|
||||
if (colidx > 0) sb.Append(", ");
|
||||
sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name));
|
||||
++colidx;
|
||||
@ -542,8 +551,10 @@ namespace FreeSql.Internal.CommonProvider
|
||||
sb.Append("(");
|
||||
var colidx2 = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false)
|
||||
{
|
||||
if (_ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||
if (col.Attribute.IsIdentity && _insertIdentity == false) continue;
|
||||
|
||||
if (colidx2 > 0) sb.Append(", ");
|
||||
object val = col.GetMapValue(d);
|
||||
if (col.Attribute.IsPrimary && col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty))
|
||||
|
@ -41,18 +41,14 @@ namespace FreeSql.Oracle.Curd
|
||||
var colidx = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (col.Attribute.IsIdentity == true)
|
||||
{
|
||||
_identCol = col;
|
||||
continue;
|
||||
}
|
||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false)
|
||||
{
|
||||
if (col.Attribute.IsIdentity) _identCol = col;
|
||||
if (_ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||
if (col.Attribute.IsIdentity && _insertIdentity == false) continue;
|
||||
|
||||
if (colidx > 0) sbtb.Append(", ");
|
||||
sbtb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name));
|
||||
++colidx;
|
||||
}
|
||||
}
|
||||
sbtb.Append(") ");
|
||||
|
||||
_params = _noneParameter ? new DbParameter[0] : new DbParameter[colidx * _source.Count];
|
||||
@ -67,8 +63,9 @@ namespace FreeSql.Oracle.Curd
|
||||
var colidx2 = 0;
|
||||
foreach (var col in _table.Columns.Values)
|
||||
{
|
||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false)
|
||||
{
|
||||
if (_ignore.ContainsKey(col.Attribute.Name)) continue;
|
||||
if (col.Attribute.IsIdentity && _insertIdentity == false) continue;
|
||||
|
||||
if (colidx2 > 0) sb.Append(", ");
|
||||
object val = col.GetMapValue(d);
|
||||
if (col.Attribute.IsPrimary && col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty))
|
||||
@ -82,7 +79,6 @@ namespace FreeSql.Oracle.Curd
|
||||
}
|
||||
++colidx2;
|
||||
}
|
||||
}
|
||||
sb.Append(")");
|
||||
++didx;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user