mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 补充 IFreeSql 增加与实现 IDisposable 接口(依然要保持单例的使用习惯);
- 增加 CurdBefore、CurdAfter AOP 方法,可监控执行增删查改; - 增加 SyncStructureBefore、SyncStructureAfter AOP 方法,可监控CodeFirst迁移;
This commit is contained in:
parent
33e992d96b
commit
b921231cb7
@ -6,6 +6,7 @@ using NpgsqlTypes;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
@ -37,6 +38,9 @@ namespace FreeSql.Tests.PostgreSQLExpression {
|
|||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Array() {
|
public void Array() {
|
||||||
|
//g.pgsql.Aop.CurdAfter = (s, e) => {
|
||||||
|
// Trace.WriteLine(e.CurdType + ": " + e.ElapsedMilliseconds + "ms " + e.Sql.Replace("\n", ""));
|
||||||
|
//};
|
||||||
IEnumerable<int> testlinqlist = new List<int>(new[] { 1, 2, 3 });
|
IEnumerable<int> testlinqlist = new List<int>(new[] { 1, 2, 3 });
|
||||||
var testlinq = select.Where(a => testlinqlist.Contains(a.testFieldInt)).ToList();
|
var testlinq = select.Where(a => testlinqlist.Contains(a.testFieldInt)).ToList();
|
||||||
|
|
||||||
|
@ -1882,129 +1882,149 @@
|
|||||||
自定义实体的属性配置,方便和多个 ORM 共同使用
|
自定义实体的属性配置,方便和多个 ORM 共同使用
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.IAop.OnUpdated">
|
<member name="P:FreeSql.IAop.CurdBefore">
|
||||||
<summary>
|
<summary>
|
||||||
IUpdate 执行成功后触发
|
增删查改,执行命令之前触发
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.IAop.OnInserted">
|
<member name="P:FreeSql.IAop.CurdAfter">
|
||||||
<summary>
|
<summary>
|
||||||
IInsert 执行成功后触发
|
增删查改,执行命令完成后触发
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.IAop.OnDeleted">
|
<member name="P:FreeSql.IAop.SyncStructureBefore">
|
||||||
<summary>
|
<summary>
|
||||||
IDeleted 执行成功后触发
|
CodeFirst迁移,执行之前触发
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.IAop.OnSelected">
|
<member name="P:FreeSql.IAop.SyncStructureAfter">
|
||||||
<summary>
|
<summary>
|
||||||
ISelect 执行成功后触发
|
CodeFirst迁移,执行完成触发
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopToListEventArgs.List">
|
<member name="P:FreeSql.Aop.ToListEventArgs.List">
|
||||||
<summary>
|
<summary>
|
||||||
可重新装饰的引用数据
|
可重新装饰的引用数据
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopWhereEventArgs.IsCancel">
|
<member name="P:FreeSql.Aop.WhereEventArgs.IsCancel">
|
||||||
<summary>
|
<summary>
|
||||||
可使上层不被执行这个条件
|
可使上层不被执行这个条件
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopParseExpressionEventArgs.FreeParse">
|
<member name="P:FreeSql.Aop.ParseExpressionEventArgs.FreeParse">
|
||||||
<summary>
|
<summary>
|
||||||
内置解析功能,可辅助您进行解析
|
内置解析功能,可辅助您进行解析
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopParseExpressionEventArgs.Expression">
|
<member name="P:FreeSql.Aop.ParseExpressionEventArgs.Expression">
|
||||||
<summary>
|
<summary>
|
||||||
需要您解析的表达式
|
需要您解析的表达式
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopParseExpressionEventArgs.Result">
|
<member name="P:FreeSql.Aop.ParseExpressionEventArgs.Result">
|
||||||
<summary>
|
<summary>
|
||||||
解析后的内容
|
解析后的内容
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopConfigEntityEventArgs.EntityType">
|
<member name="P:FreeSql.Aop.ConfigEntityEventArgs.EntityType">
|
||||||
<summary>
|
<summary>
|
||||||
实体类型
|
实体类型
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopConfigEntityEventArgs.ModifyResult">
|
<member name="P:FreeSql.Aop.ConfigEntityEventArgs.ModifyResult">
|
||||||
<summary>
|
<summary>
|
||||||
实体配置
|
实体配置
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopConfigEntityPropertyEventArgs.EntityType">
|
<member name="P:FreeSql.Aop.ConfigEntityPropertyEventArgs.EntityType">
|
||||||
<summary>
|
<summary>
|
||||||
实体类型
|
实体类型
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopConfigEntityPropertyEventArgs.Property">
|
<member name="P:FreeSql.Aop.ConfigEntityPropertyEventArgs.Property">
|
||||||
<summary>
|
<summary>
|
||||||
实体的属性
|
实体的属性
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopConfigEntityPropertyEventArgs.ModifyResult">
|
<member name="P:FreeSql.Aop.ConfigEntityPropertyEventArgs.ModifyResult">
|
||||||
<summary>
|
<summary>
|
||||||
实体的属性配置
|
实体的属性配置
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnUpdatedEventArgs.Source">
|
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.Identifier">
|
||||||
<summary>
|
<summary>
|
||||||
更新的实体
|
标识符,可将 CurdBefore 与 CurdAfter 进行匹配
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnInsertedEventArgs.Identity">
|
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.CurdType">
|
||||||
<summary>
|
<summary>
|
||||||
执行 ExecuteIdentity 方法时有效
|
操作类型
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnDeletedEventArgs.EntityType">
|
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.EntityType">
|
||||||
<summary>
|
<summary>
|
||||||
实体类型
|
实体类型
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnDeletedEventArgs.Sql">
|
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.Sql">
|
||||||
<summary>
|
<summary>
|
||||||
执行的 SQL
|
执行的 SQL
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnDeletedEventArgs.DbParms">
|
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.DbParms">
|
||||||
<summary>
|
<summary>
|
||||||
参数化命令
|
参数化命令
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnDeletedEventArgs.Affrows">
|
<member name="P:FreeSql.Aop.CurdAfterEventArgs.Exception">
|
||||||
<summary>
|
<summary>
|
||||||
执行 ExecuteAffrows 方法时有效
|
发生的错误
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnDeletedEventArgs.Returning">
|
<member name="P:FreeSql.Aop.CurdAfterEventArgs.ExecuteResult">
|
||||||
<summary>
|
<summary>
|
||||||
执行 ExecuteDeleted 方法时有效
|
执行SQL命令,返回的结果
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnSelectedEventArgs.EntityType">
|
<member name="P:FreeSql.Aop.CurdAfterEventArgs.ElapsedTicks">
|
||||||
|
<summary>
|
||||||
|
耗时(单位:Ticks)
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:FreeSql.Aop.CurdAfterEventArgs.ElapsedMilliseconds">
|
||||||
|
<summary>
|
||||||
|
耗时(单位:毫秒)
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:FreeSql.Aop.SyncStructureBeforeEventArgs.Identifier">
|
||||||
|
<summary>
|
||||||
|
标识符,可将 SyncStructureBeforeEventArgs 与 SyncStructureAfterEventArgs 进行匹配
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:FreeSql.Aop.SyncStructureBeforeEventArgs.EntityTypes">
|
||||||
<summary>
|
<summary>
|
||||||
实体类型
|
实体类型
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnSelectedEventArgs.Sql">
|
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Sql">
|
||||||
<summary>
|
<summary>
|
||||||
执行的 SQL
|
执行的 SQL
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnSelectedEventArgs.DbParms">
|
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Exception">
|
||||||
<summary>
|
<summary>
|
||||||
参数化命令
|
发生的错误
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.AopOnSelectedEventArgs.ReturnData">
|
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.ElapsedTicks">
|
||||||
<summary>
|
<summary>
|
||||||
查询返回的对象
|
耗时(单位:Ticks)
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.ElapsedMilliseconds">
|
||||||
|
<summary>
|
||||||
|
耗时(单位:毫秒)
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.ICache.Serialize">
|
<member name="P:FreeSql.ICache.Serialize">
|
||||||
|
@ -3,6 +3,7 @@ using FreeSql.DatabaseModel;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
@ -12,47 +13,50 @@ namespace FreeSql {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 监控 ToList 返回的的数据,用于拦截重新装饰
|
/// 监控 ToList 返回的的数据,用于拦截重新装饰
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopToListEventArgs> ToList { get; set; }
|
EventHandler<Aop.ToListEventArgs> ToList { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 监视 Where,包括 select/update/delete,可控制使上层不被执行。
|
/// 监视 Where,包括 select/update/delete,可控制使上层不被执行。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopWhereEventArgs> Where { get; set; }
|
EventHandler<Aop.WhereEventArgs> Where { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 可自定义解析表达式
|
/// 可自定义解析表达式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopParseExpressionEventArgs> ParseExpression { get; set; }
|
EventHandler<Aop.ParseExpressionEventArgs> ParseExpression { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自定义实体的配置,方便和多个 ORM 共同使用
|
/// 自定义实体的配置,方便和多个 ORM 共同使用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopConfigEntityEventArgs> ConfigEntity { get; set; }
|
EventHandler<Aop.ConfigEntityEventArgs> ConfigEntity { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自定义实体的属性配置,方便和多个 ORM 共同使用
|
/// 自定义实体的属性配置,方便和多个 ORM 共同使用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopConfigEntityPropertyEventArgs> ConfigEntityProperty { get; set; }
|
EventHandler<Aop.ConfigEntityPropertyEventArgs> ConfigEntityProperty { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IUpdate 执行成功后触发
|
/// 增删查改,执行命令之前触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopOnUpdatedEventArgs> OnUpdated { get; set; }
|
EventHandler<Aop.CurdBeforeEventArgs> CurdBefore { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IInsert 执行成功后触发
|
/// 增删查改,执行命令完成后触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopOnInsertedEventArgs> OnInserted { get; set; }
|
EventHandler<Aop.CurdAfterEventArgs> CurdAfter { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IDeleted 执行成功后触发
|
/// CodeFirst迁移,执行之前触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopOnDeletedEventArgs> OnDeleted { get; set; }
|
EventHandler<Aop.SyncStructureBeforeEventArgs> SyncStructureBefore { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ISelect 执行成功后触发
|
/// CodeFirst迁移,执行完成触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
EventHandler<AopOnSelectedEventArgs> OnSelected { get; set; }
|
EventHandler<Aop.SyncStructureAfterEventArgs> SyncStructureAfter { get; set; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class AopToListEventArgs : EventArgs {
|
namespace FreeSql.Aop {
|
||||||
public AopToListEventArgs(object list) {
|
public class ToListEventArgs : EventArgs {
|
||||||
|
public ToListEventArgs(object list) {
|
||||||
this.List = list;
|
this.List = list;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -60,8 +64,8 @@ namespace FreeSql {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public object List { get; }
|
public object List { get; }
|
||||||
}
|
}
|
||||||
public class AopWhereEventArgs : EventArgs {
|
public class WhereEventArgs : EventArgs {
|
||||||
public AopWhereEventArgs(params object[] parameters) {
|
public WhereEventArgs(params object[] parameters) {
|
||||||
this.Parameters = parameters;
|
this.Parameters = parameters;
|
||||||
}
|
}
|
||||||
public object[] Parameters { get; }
|
public object[] Parameters { get; }
|
||||||
@ -70,8 +74,8 @@ namespace FreeSql {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsCancel { get; set; }
|
public bool IsCancel { get; set; }
|
||||||
}
|
}
|
||||||
public class AopParseExpressionEventArgs : EventArgs {
|
public class ParseExpressionEventArgs : EventArgs {
|
||||||
public AopParseExpressionEventArgs(Expression expression, Func<Expression, string> freeParse) {
|
public ParseExpressionEventArgs(Expression expression, Func<Expression, string> freeParse) {
|
||||||
this.Expression = expression;
|
this.Expression = expression;
|
||||||
this.FreeParse = freeParse;
|
this.FreeParse = freeParse;
|
||||||
}
|
}
|
||||||
@ -90,8 +94,8 @@ namespace FreeSql {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Result { get; set; }
|
public string Result { get; set; }
|
||||||
}
|
}
|
||||||
public class AopConfigEntityEventArgs : EventArgs {
|
public class ConfigEntityEventArgs : EventArgs {
|
||||||
public AopConfigEntityEventArgs(Type entityType) {
|
public ConfigEntityEventArgs(Type entityType) {
|
||||||
this.EntityType = entityType;
|
this.EntityType = entityType;
|
||||||
this.ModifyResult = new TableAttribute();
|
this.ModifyResult = new TableAttribute();
|
||||||
}
|
}
|
||||||
@ -105,8 +109,8 @@ namespace FreeSql {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TableAttribute ModifyResult { get; }
|
public TableAttribute ModifyResult { get; }
|
||||||
}
|
}
|
||||||
public class AopConfigEntityPropertyEventArgs : EventArgs {
|
public class ConfigEntityPropertyEventArgs : EventArgs {
|
||||||
public AopConfigEntityPropertyEventArgs(Type entityType, PropertyInfo property) {
|
public ConfigEntityPropertyEventArgs(Type entityType, PropertyInfo property) {
|
||||||
this.EntityType = entityType;
|
this.EntityType = entityType;
|
||||||
this.Property = property;
|
this.Property = property;
|
||||||
this.ModifyResult = new ColumnAttribute();
|
this.ModifyResult = new ColumnAttribute();
|
||||||
@ -126,38 +130,30 @@ namespace FreeSql {
|
|||||||
public ColumnAttribute ModifyResult { get; }
|
public ColumnAttribute ModifyResult { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AopOnUpdatedEventArgs : AopOnDeletedEventArgs {
|
public class CurdBeforeEventArgs : EventArgs {
|
||||||
public AopOnUpdatedEventArgs(Type entityType, object source, string sql, DbParameter[] dbParms, int affrows, object returning)
|
public CurdBeforeEventArgs(Type entityType, CurdType curdType, string sql, DbParameter[] dbParms) :
|
||||||
: base(entityType, sql, dbParms, affrows, returning) {
|
this(Guid.NewGuid(), new Stopwatch(), entityType, curdType, sql, dbParms) {
|
||||||
this.Source = source;
|
this.Stopwatch.Start();
|
||||||
}
|
}
|
||||||
|
protected CurdBeforeEventArgs(Guid identifier, Stopwatch stopwatch, Type entityType, CurdType curdType, string sql, DbParameter[] dbParms) {
|
||||||
/// <summary>
|
this.Identifier = identifier;
|
||||||
/// 更新的实体
|
this.Stopwatch = stopwatch;
|
||||||
/// </summary>
|
|
||||||
public object Source { get; }
|
|
||||||
}
|
|
||||||
public class AopOnInsertedEventArgs : AopOnUpdatedEventArgs {
|
|
||||||
public AopOnInsertedEventArgs(Type entityType, object source, string sql, DbParameter[] dbParms, int affrows, long identity, object returning)
|
|
||||||
: base(entityType, source, sql, dbParms, affrows, returning) {
|
|
||||||
this.Identity = identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行 ExecuteIdentity 方法时有效
|
|
||||||
/// </summary>
|
|
||||||
public long? Identity { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AopOnDeletedEventArgs : EventArgs {
|
|
||||||
public AopOnDeletedEventArgs(Type entityType, string sql, DbParameter[] dbParms, int affrows, object returning) {
|
|
||||||
this.EntityType = entityType;
|
this.EntityType = entityType;
|
||||||
|
this.CurdType = curdType;
|
||||||
this.Sql = sql;
|
this.Sql = sql;
|
||||||
this.DbParms = dbParms;
|
this.DbParms = dbParms;
|
||||||
this.Affrows = affrows;
|
|
||||||
this.Returning = returning;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 标识符,可将 CurdBefore 与 CurdAfter 进行匹配
|
||||||
|
/// </summary>
|
||||||
|
public Guid Identifier { get; protected set; }
|
||||||
|
protected Stopwatch Stopwatch { get; }
|
||||||
|
internal Stopwatch StopwatchInternal => Stopwatch;
|
||||||
|
/// <summary>
|
||||||
|
/// 操作类型
|
||||||
|
/// </summary>
|
||||||
|
public CurdType CurdType { get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实体类型
|
/// 实体类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -170,39 +166,79 @@ namespace FreeSql {
|
|||||||
/// 参数化命令
|
/// 参数化命令
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DbParameter[] DbParms { get; }
|
public DbParameter[] DbParms { get; }
|
||||||
/// <summary>
|
}
|
||||||
/// 执行 ExecuteAffrows 方法时有效
|
public enum CurdType { Select, Delete, Update, Insert }
|
||||||
/// </summary>
|
public class CurdAfterEventArgs : CurdBeforeEventArgs {
|
||||||
public int Affrows { get; }
|
public CurdAfterEventArgs(CurdBeforeEventArgs before, Exception exception, object executeResult) :
|
||||||
/// <summary>
|
base(before.Identifier, before.StopwatchInternal, before.EntityType, before.CurdType, before.Sql, before.DbParms) {
|
||||||
/// 执行 ExecuteDeleted 方法时有效
|
this.Exception = exception;
|
||||||
/// </summary>
|
this.ExecuteResult = executeResult;
|
||||||
public object Returning { get; }
|
this.Stopwatch.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AopOnSelectedEventArgs : EventArgs {
|
/// <summary>
|
||||||
public AopOnSelectedEventArgs(Type entityType, string sql, DbParameter[] dbParms, object returnData) {
|
/// 发生的错误
|
||||||
this.EntityType = entityType;
|
/// </summary>
|
||||||
this.Sql = sql;
|
public Exception Exception { get; }
|
||||||
this.DbParms = dbParms;
|
/// <summary>
|
||||||
this.ReturnData = returnData;
|
/// 执行SQL命令,返回的结果
|
||||||
|
/// </summary>
|
||||||
|
public object ExecuteResult { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 耗时(单位:Ticks)
|
||||||
|
/// </summary>
|
||||||
|
public long ElapsedTicks => this.Stopwatch.ElapsedTicks;
|
||||||
|
/// <summary>
|
||||||
|
/// 耗时(单位:毫秒)
|
||||||
|
/// </summary>
|
||||||
|
public long ElapsedMilliseconds => this.Stopwatch.ElapsedMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SyncStructureBeforeEventArgs : EventArgs {
|
||||||
|
public SyncStructureBeforeEventArgs(Type[] entityTypes) :
|
||||||
|
this(Guid.NewGuid(), new Stopwatch(), entityTypes) {
|
||||||
|
this.Stopwatch.Start();
|
||||||
|
}
|
||||||
|
protected SyncStructureBeforeEventArgs(Guid identifier, Stopwatch stopwatch, Type[] entityTypes) {
|
||||||
|
this.Identifier = identifier;
|
||||||
|
this.Stopwatch = stopwatch;
|
||||||
|
this.EntityTypes = entityTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 标识符,可将 SyncStructureBeforeEventArgs 与 SyncStructureAfterEventArgs 进行匹配
|
||||||
|
/// </summary>
|
||||||
|
public Guid Identifier { get; protected set; }
|
||||||
|
protected Stopwatch Stopwatch { get; }
|
||||||
|
internal Stopwatch StopwatchInternal => Stopwatch;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实体类型
|
/// 实体类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Type EntityType { get; }
|
public Type[] EntityTypes { get; }
|
||||||
|
}
|
||||||
|
public class SyncStructureAfterEventArgs : SyncStructureBeforeEventArgs {
|
||||||
|
public SyncStructureAfterEventArgs(SyncStructureBeforeEventArgs before, string sql, Exception exception) :
|
||||||
|
base(before.Identifier, before.StopwatchInternal, before.EntityTypes) {
|
||||||
|
this.Sql = sql;
|
||||||
|
this.Exception = exception;
|
||||||
|
this.Stopwatch.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 执行的 SQL
|
/// 执行的 SQL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Sql { get; }
|
public string Sql { get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 参数化命令
|
/// 发生的错误
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DbParameter[] DbParms { get; }
|
public Exception Exception { get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询返回的对象
|
/// 耗时(单位:Ticks)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object ReturnData { get; }
|
public long ElapsedTicks => this.Stopwatch.ElapsedTicks;
|
||||||
|
/// <summary>
|
||||||
|
/// 耗时(单位:毫秒)
|
||||||
|
/// </summary>
|
||||||
|
public long ElapsedMilliseconds => this.Stopwatch.ElapsedMilliseconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -392,7 +392,7 @@ namespace FreeSql.Internal {
|
|||||||
internal string ExpressionLambdaToSql(Expression exp, ExpTSC tsc) {
|
internal string ExpressionLambdaToSql(Expression exp, ExpTSC tsc) {
|
||||||
if (exp == null) return "";
|
if (exp == null) return "";
|
||||||
if (tsc.isDisableDiyParse == false && _common._orm.Aop.ParseExpression != null) {
|
if (tsc.isDisableDiyParse == false && _common._orm.Aop.ParseExpression != null) {
|
||||||
var args = new AopParseExpressionEventArgs(exp, ukexp => ExpressionLambdaToSql(exp, tsc.CloneDisableDiyParse()));
|
var args = new Aop.ParseExpressionEventArgs(exp, ukexp => ExpressionLambdaToSql(exp, tsc.CloneDisableDiyParse()));
|
||||||
_common._orm.Aop.ParseExpression?.Invoke(this, args);
|
_common._orm.Aop.ParseExpression?.Invoke(this, args);
|
||||||
if (string.IsNullOrEmpty(args.Result) == false) return args.Result;
|
if (string.IsNullOrEmpty(args.Result) == false) return args.Result;
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@ using System.Text;
|
|||||||
|
|
||||||
namespace FreeSql.Internal.CommonProvider {
|
namespace FreeSql.Internal.CommonProvider {
|
||||||
class AopProvider : IAop {
|
class AopProvider : IAop {
|
||||||
public EventHandler<AopToListEventArgs> ToList { get; set; }
|
public EventHandler<Aop.ToListEventArgs> ToList { get; set; }
|
||||||
public EventHandler<AopWhereEventArgs> Where { get; set; }
|
public EventHandler<Aop.WhereEventArgs> Where { get; set; }
|
||||||
public EventHandler<AopParseExpressionEventArgs> ParseExpression { get; set; }
|
public EventHandler<Aop.ParseExpressionEventArgs> ParseExpression { get; set; }
|
||||||
public EventHandler<AopConfigEntityEventArgs> ConfigEntity { get; set; }
|
public EventHandler<Aop.ConfigEntityEventArgs> ConfigEntity { get; set; }
|
||||||
public EventHandler<AopConfigEntityPropertyEventArgs> ConfigEntityProperty { get; set; }
|
public EventHandler<Aop.ConfigEntityPropertyEventArgs> ConfigEntityProperty { get; set; }
|
||||||
public EventHandler<AopOnUpdatedEventArgs> OnUpdated { get; set; }
|
public EventHandler<Aop.CurdBeforeEventArgs> CurdBefore { get; set; }
|
||||||
public EventHandler<AopOnInsertedEventArgs> OnInserted { get; set; }
|
public EventHandler<Aop.CurdAfterEventArgs> CurdAfter { get; set; }
|
||||||
public EventHandler<AopOnDeletedEventArgs> OnDeleted { get; set; }
|
public EventHandler<Aop.SyncStructureBeforeEventArgs> SyncStructureBefore { get; set; }
|
||||||
public EventHandler<AopOnSelectedEventArgs> OnSelected { get; set; }
|
public EventHandler<Aop.SyncStructureAfterEventArgs> SyncStructureAfter { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,19 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||||
_orm.Aop.OnDeleted?.Invoke(this, new AopOnDeletedEventArgs(_table.Type, sql, dbParms, affrows, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var affrows = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
this.ClearData();
|
this.ClearData();
|
||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
@ -60,8 +71,19 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||||
_orm.Aop.OnDeleted?.Invoke(this, new AopOnDeletedEventArgs(_table.Type, sql, dbParms, affrows, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var affrows = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
this.ClearData();
|
this.ClearData();
|
||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
@ -71,8 +93,8 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
public IDelete<T1> Where(Expression<Func<T1, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null));
|
public IDelete<T1> Where(Expression<Func<T1, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null));
|
||||||
public IDelete<T1> Where(string sql, object parms = null) {
|
public IDelete<T1> Where(string sql, object parms = null) {
|
||||||
if (string.IsNullOrEmpty(sql)) return this;
|
if (string.IsNullOrEmpty(sql)) return this;
|
||||||
var args = new AopWhereEventArgs(sql, parms);
|
var args = new Aop.WhereEventArgs(sql, parms);
|
||||||
_orm.Aop.Where?.Invoke(this, new AopWhereEventArgs(sql, parms));
|
_orm.Aop.Where?.Invoke(this, new Aop.WhereEventArgs(sql, parms));
|
||||||
if (args.IsCancel == true) return this;
|
if (args.IsCancel == true) return this;
|
||||||
|
|
||||||
if (++_whereTimes > 1) _where.Append(" AND ");
|
if (++_whereTimes > 1) _where.Append(" AND ");
|
||||||
|
@ -325,14 +325,38 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
internal int RawExecuteAffrows() {
|
internal int RawExecuteAffrows() {
|
||||||
var sql = ToSql();
|
var sql = ToSql();
|
||||||
var affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, affrows, 0, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var affrows = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
async internal Task<int> RawExecuteAffrowsAsync() {
|
async internal Task<int> RawExecuteAffrowsAsync() {
|
||||||
var sql = ToSql();
|
var sql = ToSql();
|
||||||
var affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, affrows, 0, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var affrows = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
internal abstract long RawExecuteIdentity();
|
internal abstract long RawExecuteIdentity();
|
||||||
|
@ -217,8 +217,19 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
return _orm.Cache.Shell(_cache.key, _cache.seconds, () => {
|
return _orm.Cache.Shell(_cache.key, _cache.seconds, () => {
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = _orm.Ado.ExecuteDataTable(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
DataTable ret = null;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.ExecuteDataTable(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -228,8 +239,19 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
return _orm.Cache.ShellAsync(_cache.key, _cache.seconds, async () => {
|
return _orm.Cache.ShellAsync(_cache.key, _cache.seconds, async () => {
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = await _orm.Ado.ExecuteDataTableAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
DataTable ret = null;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.ExecuteDataTableAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -239,15 +261,25 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = sql;
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = sql;
|
||||||
|
|
||||||
return _orm.Cache.Shell(_cache.key, _cache.seconds, () => {
|
return _orm.Cache.Shell(_cache.key, _cache.seconds, () => {
|
||||||
var ret = new List<TTuple>();
|
|
||||||
var type = typeof(TTuple);
|
var type = typeof(TTuple);
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<TTuple>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
_orm.Ado.ExecuteReader(_connection, _transaction, dr => {
|
_orm.Ado.ExecuteReader(_connection, _transaction, dr => {
|
||||||
var read = Utils.ExecuteArrayRowReadClassOrTuple(type, null, dr, 0, _commonUtils);
|
var read = Utils.ExecuteArrayRowReadClassOrTuple(type, null, dr, 0, _commonUtils);
|
||||||
ret.Add((TTuple) read.Value);
|
ret.Add((TTuple)read.Value);
|
||||||
}, CommandType.Text, sql, dbParms);
|
}, CommandType.Text, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
} catch (Exception ex) {
|
||||||
_orm.Aop.ToList?.Invoke(this, new AopToListEventArgs(ret));
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
_orm.Aop.ToList?.Invoke(this, new Aop.ToListEventArgs(ret));
|
||||||
_trackToList?.Invoke(ret);
|
_trackToList?.Invoke(ret);
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
@ -257,16 +289,26 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = sql;
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = sql;
|
||||||
|
|
||||||
return _orm.Cache.ShellAsync(_cache.key, _cache.seconds, async () => {
|
return _orm.Cache.ShellAsync(_cache.key, _cache.seconds, async () => {
|
||||||
var ret = new List<TTuple>();
|
|
||||||
var type = typeof(TTuple);
|
var type = typeof(TTuple);
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<TTuple>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
await _orm.Ado.ExecuteReaderAsync(_connection, _transaction, dr => {
|
await _orm.Ado.ExecuteReaderAsync(_connection, _transaction, dr => {
|
||||||
var read = Utils.ExecuteArrayRowReadClassOrTuple(type, null, dr, 0, _commonUtils);
|
var read = Utils.ExecuteArrayRowReadClassOrTuple(type, null, dr, 0, _commonUtils);
|
||||||
ret.Add((TTuple) read.Value);
|
ret.Add((TTuple)read.Value);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}, CommandType.Text, sql, dbParms);
|
}, CommandType.Text, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
} catch (Exception ex) {
|
||||||
_orm.Aop.ToList?.Invoke(this, new AopToListEventArgs(ret));
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
_orm.Aop.ToList?.Invoke(this, new Aop.ToListEventArgs(ret));
|
||||||
_trackToList?.Invoke(ret);
|
_trackToList?.Invoke(ret);
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
@ -276,13 +318,23 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
|
||||||
|
|
||||||
return _orm.Cache.Shell(_cache.key, _cache.seconds, () => {
|
return _orm.Cache.Shell(_cache.key, _cache.seconds, () => {
|
||||||
var ret = new List<T1>();
|
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
_orm.Ado.ExecuteReader(_connection, _transaction, dr => {
|
_orm.Ado.ExecuteReader(_connection, _transaction, dr => {
|
||||||
ret.Add(af.Read(_orm, dr));
|
ret.Add(af.Read(_orm, dr));
|
||||||
}, CommandType.Text, sql, dbParms);
|
}, CommandType.Text, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
} catch (Exception ex) {
|
||||||
_orm.Aop.ToList?.Invoke(this, new AopToListEventArgs(ret));
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
_orm.Aop.ToList?.Invoke(this, new Aop.ToListEventArgs(ret));
|
||||||
_trackToList?.Invoke(ret);
|
_trackToList?.Invoke(ret);
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
@ -292,14 +344,24 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
|
||||||
|
|
||||||
return await _orm.Cache.ShellAsync(_cache.key, _cache.seconds, async () => {
|
return await _orm.Cache.ShellAsync(_cache.key, _cache.seconds, async () => {
|
||||||
var ret = new List<T1>();
|
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
await _orm.Ado.ExecuteReaderAsync(_connection, _transaction, dr => {
|
await _orm.Ado.ExecuteReaderAsync(_connection, _transaction, dr => {
|
||||||
ret.Add(af.Read(_orm, dr));
|
ret.Add(af.Read(_orm, dr));
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}, CommandType.Text, sql, dbParms);
|
}, CommandType.Text, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
} catch (Exception ex) {
|
||||||
_orm.Aop.ToList?.Invoke(this, new AopToListEventArgs(ret));
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
_orm.Aop.ToList?.Invoke(this, new Aop.ToListEventArgs(ret));
|
||||||
_trackToList?.Invoke(ret);
|
_trackToList?.Invoke(ret);
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
@ -325,15 +387,25 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
|
||||||
|
|
||||||
return _orm.Cache.Shell(_cache.key, _cache.seconds, () => {
|
return _orm.Cache.Shell(_cache.key, _cache.seconds, () => {
|
||||||
var ret = new List<TReturn>();
|
|
||||||
var type = typeof(TReturn);
|
var type = typeof(TReturn);
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<TReturn>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
_orm.Ado.ExecuteReader(_connection, _transaction, dr => {
|
_orm.Ado.ExecuteReader(_connection, _transaction, dr => {
|
||||||
var index = -1;
|
var index = -1;
|
||||||
ret.Add((TReturn) _commonExpression.ReadAnonymous(af.map, dr, ref index, false));
|
ret.Add((TReturn)_commonExpression.ReadAnonymous(af.map, dr, ref index, false));
|
||||||
}, CommandType.Text, sql, dbParms);
|
}, CommandType.Text, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
} catch (Exception ex) {
|
||||||
_orm.Aop.ToList?.Invoke(this, new AopToListEventArgs(ret));
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
_orm.Aop.ToList?.Invoke(this, new Aop.ToListEventArgs(ret));
|
||||||
_trackToList?.Invoke(ret);
|
_trackToList?.Invoke(ret);
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
@ -343,16 +415,26 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
|
||||||
|
|
||||||
return await _orm.Cache.ShellAsync(_cache.key, _cache.seconds, async () => {
|
return await _orm.Cache.ShellAsync(_cache.key, _cache.seconds, async () => {
|
||||||
var ret = new List<TReturn>();
|
|
||||||
var type = typeof(TReturn);
|
var type = typeof(TReturn);
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<TReturn>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
await _orm.Ado.ExecuteReaderAsync(_connection, _transaction, dr => {
|
await _orm.Ado.ExecuteReaderAsync(_connection, _transaction, dr => {
|
||||||
var index = -1;
|
var index = -1;
|
||||||
ret.Add((TReturn) _commonExpression.ReadAnonymous(af.map, dr, ref index, false));
|
ret.Add((TReturn)_commonExpression.ReadAnonymous(af.map, dr, ref index, false));
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}, CommandType.Text, sql, dbParms);
|
}, CommandType.Text, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
} catch (Exception ex) {
|
||||||
_orm.Aop.ToList?.Invoke(this, new AopToListEventArgs(ret));
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
_orm.Aop.ToList?.Invoke(this, new Aop.ToListEventArgs(ret));
|
||||||
_trackToList?.Invoke(ret);
|
_trackToList?.Invoke(ret);
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
@ -680,8 +762,8 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
public TSelect Where(string sql, object parms = null) => this.WhereIf(true, sql, parms);
|
public TSelect Where(string sql, object parms = null) => this.WhereIf(true, sql, parms);
|
||||||
public TSelect WhereIf(bool condition, string sql, object parms = null) {
|
public TSelect WhereIf(bool condition, string sql, object parms = null) {
|
||||||
if (condition == false || string.IsNullOrEmpty(sql)) return this as TSelect;
|
if (condition == false || string.IsNullOrEmpty(sql)) return this as TSelect;
|
||||||
var args = new AopWhereEventArgs(sql, parms);
|
var args = new Aop.WhereEventArgs(sql, parms);
|
||||||
_orm.Aop.Where?.Invoke(this, new AopWhereEventArgs(sql, parms));
|
_orm.Aop.Where?.Invoke(this, new Aop.WhereEventArgs(sql, parms));
|
||||||
if (args.IsCancel == true) return this as TSelect;
|
if (args.IsCancel == true) return this as TSelect;
|
||||||
|
|
||||||
_where.Append(" AND (").Append(sql).Append(")");
|
_where.Append(" AND (").Append(sql).Append(")");
|
||||||
@ -732,15 +814,37 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
protected DataTable InternalToDataTable(Expression select) {
|
protected DataTable InternalToDataTable(Expression select) {
|
||||||
var sql = this.InternalToSql<int>(select);
|
var sql = this.InternalToSql<int>(select);
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = _orm.Ado.ExecuteDataTable(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
DataTable ret = null;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.ExecuteDataTable(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
async protected Task<DataTable> InternalToDataTableAsync(Expression select) {
|
async protected Task<DataTable> InternalToDataTableAsync(Expression select) {
|
||||||
var sql = this.InternalToSql<int>(select);
|
var sql = this.InternalToSql<int>(select);
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = await _orm.Ado.ExecuteDataTableAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, Aop.CurdType.Select, sql, dbParms);
|
||||||
_orm.Aop.OnSelected?.Invoke(this, new AopOnSelectedEventArgs(_tables[0].Table.Type, sql, dbParms, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
DataTable ret = null;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.ExecuteDataTableAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,18 +240,42 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||||
var affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||||
_orm.Aop.OnUpdated?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, null, sql, dbParms, affrows, 0, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var affrows = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
ValidateVersionAndThrow(affrows);
|
ValidateVersionAndThrow(affrows);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
async internal Task<int> RawExecuteAffrowsAsync() {
|
async internal Task<int> RawExecuteAffrowsAsync() {
|
||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||||
var affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||||
_orm.Aop.OnUpdated?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, null, sql, dbParms, affrows, 0, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var affrows = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
ValidateVersionAndThrow(affrows);
|
ValidateVersionAndThrow(affrows);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
internal abstract List<T1> RawExecuteUpdated();
|
internal abstract List<T1> RawExecuteUpdated();
|
||||||
@ -343,8 +367,8 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
public IUpdate<T1> Where(Expression<Func<T1, bool>> expression) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, expression?.Body, null));
|
public IUpdate<T1> Where(Expression<Func<T1, bool>> expression) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, expression?.Body, null));
|
||||||
public IUpdate<T1> Where(string sql, object parms = null) {
|
public IUpdate<T1> Where(string sql, object parms = null) {
|
||||||
if (string.IsNullOrEmpty(sql)) return this;
|
if (string.IsNullOrEmpty(sql)) return this;
|
||||||
var args = new AopWhereEventArgs(sql, parms);
|
var args = new Aop.WhereEventArgs(sql, parms);
|
||||||
_orm.Aop.Where?.Invoke(this, new AopWhereEventArgs(sql, parms));
|
_orm.Aop.Where?.Invoke(this, new Aop.WhereEventArgs(sql, parms));
|
||||||
if (args.IsCancel == true) return this;
|
if (args.IsCancel == true) return this;
|
||||||
|
|
||||||
_where.Append(" AND (").Append(sql).Append(")");
|
_where.Append(" AND (").Append(sql).Append(")");
|
||||||
|
@ -61,7 +61,7 @@ namespace FreeSql.Internal {
|
|||||||
internal TableAttribute GetEntityTableAttribute(Type type) {
|
internal TableAttribute GetEntityTableAttribute(Type type) {
|
||||||
TableAttribute attr = null;
|
TableAttribute attr = null;
|
||||||
if (_orm.Aop.ConfigEntity != null) {
|
if (_orm.Aop.ConfigEntity != null) {
|
||||||
var aope = new AopConfigEntityEventArgs(type);
|
var aope = new Aop.ConfigEntityEventArgs(type);
|
||||||
_orm.Aop.ConfigEntity(_orm, aope);
|
_orm.Aop.ConfigEntity(_orm, aope);
|
||||||
attr = aope.ModifyResult;
|
attr = aope.ModifyResult;
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ namespace FreeSql.Internal {
|
|||||||
internal ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto) {
|
internal ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto) {
|
||||||
ColumnAttribute attr = null;
|
ColumnAttribute attr = null;
|
||||||
if (_orm.Aop.ConfigEntityProperty != null) {
|
if (_orm.Aop.ConfigEntityProperty != null) {
|
||||||
var aope = new AopConfigEntityPropertyEventArgs(type, proto);
|
var aope = new Aop.ConfigEntityPropertyEventArgs(type, proto);
|
||||||
_orm.Aop.ConfigEntityProperty(_orm, aope);
|
_orm.Aop.ConfigEntityProperty(_orm, aope);
|
||||||
attr = aope.ModifyResult;
|
attr = aope.ModifyResult;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using FreeSql.Internal;
|
using FreeSql.Internal;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -26,8 +27,19 @@ namespace FreeSql.MySql.Curd {
|
|||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||||
_orm.Aop.OnDeleted?.Invoke(this, new AopOnDeletedEventArgs(_table.Type, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
this.ClearData();
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -46,8 +58,19 @@ namespace FreeSql.MySql.Curd {
|
|||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||||
_orm.Aop.OnDeleted?.Invoke(this, new AopOnDeletedEventArgs(_table.Type, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
this.ClearData();
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using FreeSql.Internal;
|
using FreeSql.Internal;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -24,8 +25,20 @@ namespace FreeSql.MySql.Curd {
|
|||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
sql = string.Concat(sql, "; SELECT LAST_INSERT_ID();");
|
sql = string.Concat(sql, "; SELECT LAST_INSERT_ID();");
|
||||||
var ret = long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng) ? trylng : 0;
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, ret, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng) ? trylng : 0;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<long> RawExecuteIdentityAsync() {
|
async internal override Task<long> RawExecuteIdentityAsync() {
|
||||||
@ -33,8 +46,20 @@ namespace FreeSql.MySql.Curd {
|
|||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
sql = string.Concat(sql, "; SELECT LAST_INSERT_ID();");
|
sql = string.Concat(sql, "; SELECT LAST_INSERT_ID();");
|
||||||
var ret = long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng) ? trylng : 0;
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, ret, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng) ? trylng : 0;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
internal override List<T1> RawExecuteInserted() {
|
internal override List<T1> RawExecuteInserted() {
|
||||||
@ -51,8 +76,20 @@ namespace FreeSql.MySql.Curd {
|
|||||||
++colidx;
|
++colidx;
|
||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<List<T1>> RawExecuteInsertedAsync() {
|
async internal override Task<List<T1>> RawExecuteInsertedAsync() {
|
||||||
@ -69,8 +106,20 @@ namespace FreeSql.MySql.Curd {
|
|||||||
++colidx;
|
++colidx;
|
||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using FreeSql.Internal;
|
using FreeSql.Internal;
|
||||||
using FreeSql.Internal.Model;
|
using FreeSql.Internal.Model;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -35,9 +36,21 @@ namespace FreeSql.MySql.Curd {
|
|||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||||
_orm.Aop.OnUpdated?.Invoke(this, new AopOnUpdatedEventArgs(_table.Type, _source, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
ValidateVersionAndThrow(ret.Count);
|
ValidateVersionAndThrow(ret.Count);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<List<T1>> RawExecuteUpdatedAsync() {
|
async internal override Task<List<T1>> RawExecuteUpdatedAsync() {
|
||||||
@ -55,9 +68,21 @@ namespace FreeSql.MySql.Curd {
|
|||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||||
_orm.Aop.OnUpdated?.Invoke(this, new AopOnUpdatedEventArgs(_table.Type, _source, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
ValidateVersionAndThrow(ret.Count);
|
ValidateVersionAndThrow(ret.Count);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,8 +292,13 @@ where a.constraint_schema IN ({0}) and a.table_name IN ({1})".FormatMySql(tboldn
|
|||||||
if (entityTypes == null) return true;
|
if (entityTypes == null) return true;
|
||||||
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
||||||
if (syncTypes.Any() == false) return true;
|
if (syncTypes.Any() == false) return true;
|
||||||
|
var before = new Aop.SyncStructureBeforeEventArgs(entityTypes);
|
||||||
|
_orm.Aop.SyncStructureBefore?.Invoke(this, before);
|
||||||
|
Exception exception = null;
|
||||||
|
string ddl = null;
|
||||||
|
try {
|
||||||
lock (syncStructureLock) {
|
lock (syncStructureLock) {
|
||||||
var ddl = this.GetComparisonDDLStatements(syncTypes);
|
ddl = this.GetComparisonDDLStatements(syncTypes);
|
||||||
if (string.IsNullOrEmpty(ddl)) {
|
if (string.IsNullOrEmpty(ddl)) {
|
||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return true;
|
return true;
|
||||||
@ -302,6 +307,13 @@ where a.constraint_schema IN ({0}) and a.table_name IN ({1})".FormatMySql(tboldn
|
|||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return affrows > 0;
|
return affrows > 0;
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.SyncStructureAfterEventArgs(before, ddl, exception);
|
||||||
|
_orm.Aop.SyncStructureAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
||||||
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
||||||
|
@ -84,9 +84,23 @@ namespace FreeSql.Oracle.Curd {
|
|||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
Aop.CurdBeforeEventArgs before = null;
|
||||||
|
|
||||||
if (_identCol == null || _source.Count > 1) {
|
if (_identCol == null || _source.Count > 1) {
|
||||||
_orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name);
|
var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name);
|
||||||
@ -94,18 +108,42 @@ namespace FreeSql.Oracle.Curd {
|
|||||||
identParam.Direction = ParameterDirection.Output;
|
identParam.Direction = ParameterDirection.Output;
|
||||||
sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}";
|
sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}";
|
||||||
var dbParms = _params.Concat(new[] { identParam }).ToArray();
|
var dbParms = _params.Concat(new[] { identParam }).ToArray();
|
||||||
|
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
try {
|
||||||
_orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, dbParms);
|
_orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
long.TryParse(string.Concat(identParam.Value), out var trylng);
|
long.TryParse(string.Concat(identParam.Value), out ret);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, dbParms, 0, trylng, null));
|
} catch (Exception ex) {
|
||||||
return trylng;
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<long> RawExecuteIdentityAsync() {
|
async internal override Task<long> RawExecuteIdentityAsync() {
|
||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
Aop.CurdBeforeEventArgs before = null;
|
||||||
|
|
||||||
if (_identCol == null || _source.Count > 1) {
|
if (_identCol == null || _source.Count > 1) {
|
||||||
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name);
|
var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name);
|
||||||
@ -113,10 +151,20 @@ namespace FreeSql.Oracle.Curd {
|
|||||||
identParam.Direction = ParameterDirection.Output;
|
identParam.Direction = ParameterDirection.Output;
|
||||||
sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}";
|
sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}";
|
||||||
var dbParms = _params.Concat(new[] { identParam }).ToArray();
|
var dbParms = _params.Concat(new[] { identParam }).ToArray();
|
||||||
|
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
try {
|
||||||
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
long.TryParse(string.Concat(identParam.Value), out var trylng);
|
long.TryParse(string.Concat(identParam.Value), out ret);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, dbParms, 0, trylng, null));
|
} catch (Exception ex) {
|
||||||
return trylng;
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override List<T1> RawExecuteInserted() {
|
internal override List<T1> RawExecuteInserted() {
|
||||||
|
@ -339,8 +339,13 @@ and a.owner in ({0}) and a.table_name in ({1})".FormatMySql(tboldname ?? tbname)
|
|||||||
if (entityTypes == null) return true;
|
if (entityTypes == null) return true;
|
||||||
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
||||||
if (syncTypes.Any() == false) return true;
|
if (syncTypes.Any() == false) return true;
|
||||||
|
var before = new Aop.SyncStructureBeforeEventArgs(entityTypes);
|
||||||
|
_orm.Aop.SyncStructureBefore?.Invoke(this, before);
|
||||||
|
Exception exception = null;
|
||||||
|
string ddl = null;
|
||||||
|
try {
|
||||||
lock (syncStructureLock) {
|
lock (syncStructureLock) {
|
||||||
var ddl = this.GetComparisonDDLStatements(syncTypes);
|
ddl = this.GetComparisonDDLStatements(syncTypes);
|
||||||
if (string.IsNullOrEmpty(ddl)) {
|
if (string.IsNullOrEmpty(ddl)) {
|
||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return true;
|
return true;
|
||||||
@ -349,6 +354,13 @@ and a.owner in ({0}) and a.table_name in ({1})".FormatMySql(tboldname ?? tbname)
|
|||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return affrows > 0;
|
return affrows > 0;
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.SyncStructureAfterEventArgs(before, ddl, exception);
|
||||||
|
_orm.Aop.SyncStructureAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
||||||
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using FreeSql.Internal;
|
using FreeSql.Internal;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -26,8 +27,19 @@ namespace FreeSql.PostgreSQL.Curd {
|
|||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||||
_orm.Aop.OnDeleted?.Invoke(this, new AopOnDeletedEventArgs(_table.Type, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
this.ClearData();
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -46,8 +58,19 @@ namespace FreeSql.PostgreSQL.Curd {
|
|||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||||
_orm.Aop.OnDeleted?.Invoke(this, new AopOnDeletedEventArgs(_table.Type, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
this.ClearData();
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using FreeSql.Internal;
|
using FreeSql.Internal;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -24,31 +25,79 @@ namespace FreeSql.PostgreSQL.Curd {
|
|||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
Aop.CurdBeforeEventArgs before = null;
|
||||||
|
|
||||||
var identCols = _table.Columns.Where(a => a.Value.Attribute.IsIdentity == true);
|
var identCols = _table.Columns.Where(a => a.Value.Attribute.IsIdentity == true);
|
||||||
if (identCols.Any() == false) {
|
if (identCols.Any() == false) {
|
||||||
_orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
sql = string.Concat(sql, " RETURNING ", _commonUtils.QuoteSqlName(identCols.First().Value.Attribute.Name));
|
sql = string.Concat(sql, " RETURNING ", _commonUtils.QuoteSqlName(identCols.First().Value.Attribute.Name));
|
||||||
long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng);
|
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, trylng, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
return trylng;
|
try {
|
||||||
|
long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _params)), out ret);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<long> RawExecuteIdentityAsync() {
|
async internal override Task<long> RawExecuteIdentityAsync() {
|
||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
Aop.CurdBeforeEventArgs before = null;
|
||||||
|
|
||||||
var identCols = _table.Columns.Where(a => a.Value.Attribute.IsIdentity == true);
|
var identCols = _table.Columns.Where(a => a.Value.Attribute.IsIdentity == true);
|
||||||
if (identCols.Any() == false) {
|
if (identCols.Any() == false) {
|
||||||
await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
sql = string.Concat(sql, " RETURNING ", _commonUtils.QuoteSqlName(identCols.First().Value.Attribute.Name));
|
sql = string.Concat(sql, " RETURNING ", _commonUtils.QuoteSqlName(identCols.First().Value.Attribute.Name));
|
||||||
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng);
|
before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, trylng, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
return trylng;
|
try {
|
||||||
|
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _params)), out ret);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override List<T1> RawExecuteInserted() {
|
internal override List<T1> RawExecuteInserted() {
|
||||||
@ -65,8 +114,20 @@ namespace FreeSql.PostgreSQL.Curd {
|
|||||||
++colidx;
|
++colidx;
|
||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<List<T1>> RawExecuteInsertedAsync() {
|
async internal override Task<List<T1>> RawExecuteInsertedAsync() {
|
||||||
@ -83,8 +144,20 @@ namespace FreeSql.PostgreSQL.Curd {
|
|||||||
++colidx;
|
++colidx;
|
||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using FreeSql.Internal;
|
using FreeSql.Internal;
|
||||||
using FreeSql.Internal.Model;
|
using FreeSql.Internal.Model;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -35,9 +36,21 @@ namespace FreeSql.PostgreSQL.Curd {
|
|||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||||
_orm.Aop.OnUpdated?.Invoke(this, new AopOnUpdatedEventArgs(_table.Type, _source, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
ValidateVersionAndThrow(ret.Count);
|
ValidateVersionAndThrow(ret.Count);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<List<T1>> RawExecuteUpdatedAsync() {
|
async internal override Task<List<T1>> RawExecuteUpdatedAsync() {
|
||||||
@ -55,9 +68,21 @@ namespace FreeSql.PostgreSQL.Curd {
|
|||||||
}
|
}
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||||
_orm.Aop.OnUpdated?.Invoke(this, new AopOnUpdatedEventArgs(_table.Type, _source, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
ValidateVersionAndThrow(ret.Count);
|
ValidateVersionAndThrow(ret.Count);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,8 +344,13 @@ where pg_namespace.nspname={0} and pg_class.relname={1} and pg_constraint.contyp
|
|||||||
if (entityTypes == null) return true;
|
if (entityTypes == null) return true;
|
||||||
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
||||||
if (syncTypes.Any() == false) return true;
|
if (syncTypes.Any() == false) return true;
|
||||||
|
var before = new Aop.SyncStructureBeforeEventArgs(entityTypes);
|
||||||
|
_orm.Aop.SyncStructureBefore?.Invoke(this, before);
|
||||||
|
Exception exception = null;
|
||||||
|
string ddl = null;
|
||||||
|
try {
|
||||||
lock (syncStructureLock) {
|
lock (syncStructureLock) {
|
||||||
var ddl = this.GetComparisonDDLStatements(syncTypes);
|
ddl = this.GetComparisonDDLStatements(syncTypes);
|
||||||
if (string.IsNullOrEmpty(ddl)) {
|
if (string.IsNullOrEmpty(ddl)) {
|
||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return true;
|
return true;
|
||||||
@ -354,6 +359,13 @@ where pg_namespace.nspname={0} and pg_class.relname={1} and pg_constraint.contyp
|
|||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return affrows > 0;
|
return affrows > 0;
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.SyncStructureAfterEventArgs(before, ddl, exception);
|
||||||
|
_orm.Aop.SyncStructureAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
||||||
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
||||||
|
@ -32,8 +32,19 @@ namespace FreeSql.SqlServer.Curd {
|
|||||||
|
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||||
_orm.Aop.OnDeleted?.Invoke(this, new AopOnDeletedEventArgs(_table.Type, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
this.ClearData();
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -57,8 +68,19 @@ namespace FreeSql.SqlServer.Curd {
|
|||||||
|
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.ToArray();
|
var dbParms = _params.ToArray();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Delete, sql, dbParms);
|
||||||
_orm.Aop.OnDeleted?.Invoke(this, new AopOnDeletedEventArgs(_table.Type, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
this.ClearData();
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -27,18 +27,42 @@ namespace FreeSql.SqlServer.Curd {
|
|||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
sql = string.Concat(sql, "; SELECT SCOPE_IDENTITY();");
|
sql = string.Concat(sql, "; SELECT SCOPE_IDENTITY();");
|
||||||
long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, trylng, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
return trylng;
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _params)), out ret);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<long> RawExecuteIdentityAsync() {
|
async internal override Task<long> RawExecuteIdentityAsync() {
|
||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
sql = string.Concat(sql, "; SELECT SCOPE_IDENTITY();");
|
sql = string.Concat(sql, "; SELECT SCOPE_IDENTITY();");
|
||||||
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, trylng, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
return trylng;
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _params)), out ret);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override List<T1> RawExecuteInserted() {
|
internal override List<T1> RawExecuteInserted() {
|
||||||
@ -60,8 +84,20 @@ namespace FreeSql.SqlServer.Curd {
|
|||||||
sb.Append(sql.Substring(validx + 1));
|
sb.Append(sql.Substring(validx + 1));
|
||||||
|
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<List<T1>> RawExecuteInsertedAsync() {
|
async internal override Task<List<T1>> RawExecuteInsertedAsync() {
|
||||||
@ -83,8 +119,20 @@ namespace FreeSql.SqlServer.Curd {
|
|||||||
sb.Append(sql.Substring(validx + 1));
|
sb.Append(sql.Substring(validx + 1));
|
||||||
|
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _params);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,21 @@ namespace FreeSql.SqlServer.Curd {
|
|||||||
|
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||||
var ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||||
_orm.Aop.OnUpdated?.Invoke(this, new AopOnUpdatedEventArgs(_table.Type, _source, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
ValidateVersionAndThrow(ret.Count);
|
ValidateVersionAndThrow(ret.Count);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<List<T1>> RawExecuteUpdatedAsync() {
|
async internal override Task<List<T1>> RawExecuteUpdatedAsync() {
|
||||||
@ -66,9 +78,21 @@ namespace FreeSql.SqlServer.Curd {
|
|||||||
|
|
||||||
sql = sb.ToString();
|
sql = sb.ToString();
|
||||||
var dbParms = _params.Concat(_paramsSource).ToArray();
|
var dbParms = _params.Concat(_paramsSource).ToArray();
|
||||||
var ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Update, sql, dbParms);
|
||||||
_orm.Aop.OnUpdated?.Invoke(this, new AopOnUpdatedEventArgs(_table.Type, _source, sql, dbParms, 0, ret));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
|
var ret = new List<T1>();
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||||
ValidateVersionAndThrow(ret.Count);
|
ValidateVersionAndThrow(ret.Count);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,8 +333,13 @@ use " + database, tboldname ?? tbname);
|
|||||||
if (entityTypes == null) return true;
|
if (entityTypes == null) return true;
|
||||||
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
||||||
if (syncTypes.Any() == false) return true;
|
if (syncTypes.Any() == false) return true;
|
||||||
|
var before = new Aop.SyncStructureBeforeEventArgs(entityTypes);
|
||||||
|
_orm.Aop.SyncStructureBefore?.Invoke(this, before);
|
||||||
|
Exception exception = null;
|
||||||
|
string ddl = null;
|
||||||
|
try {
|
||||||
lock (syncStructureLock) {
|
lock (syncStructureLock) {
|
||||||
var ddl = this.GetComparisonDDLStatements(syncTypes);
|
ddl = this.GetComparisonDDLStatements(syncTypes);
|
||||||
if (string.IsNullOrEmpty(ddl)) {
|
if (string.IsNullOrEmpty(ddl)) {
|
||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return true;
|
return true;
|
||||||
@ -343,6 +348,13 @@ use " + database, tboldname ?? tbname);
|
|||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return affrows > 0;
|
return affrows > 0;
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.SyncStructureAfterEventArgs(before, ddl, exception);
|
||||||
|
_orm.Aop.SyncStructureAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
||||||
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
||||||
|
@ -26,18 +26,42 @@ namespace FreeSql.Sqlite.Curd {
|
|||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
sql = string.Concat(sql, "; SELECT last_insert_rowid();");
|
sql = string.Concat(sql, "; SELECT last_insert_rowid();");
|
||||||
long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, trylng, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
return trylng;
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _params)), out ret);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
async internal override Task<long> RawExecuteIdentityAsync() {
|
async internal override Task<long> RawExecuteIdentityAsync() {
|
||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
|
|
||||||
sql = string.Concat(sql, "; SELECT last_insert_rowid();");
|
sql = string.Concat(sql, "; SELECT last_insert_rowid();");
|
||||||
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _params)), out var trylng);
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, Aop.CurdType.Insert, sql, _params);
|
||||||
_orm.Aop.OnInserted?.Invoke(this, new AopOnInsertedEventArgs(_table.Type, _source, sql, _params, 0, trylng, null));
|
_orm.Aop.CurdBefore?.Invoke(this, before);
|
||||||
return trylng;
|
long ret = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _params)), out ret);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
this.ClearData();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
internal override List<T1> RawExecuteInserted() {
|
internal override List<T1> RawExecuteInserted() {
|
||||||
var sql = this.ToSql();
|
var sql = this.ToSql();
|
||||||
|
@ -256,8 +256,13 @@ namespace FreeSql.Sqlite {
|
|||||||
if (entityTypes == null) return true;
|
if (entityTypes == null) return true;
|
||||||
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false).ToArray();
|
||||||
if (syncTypes.Any() == false) return true;
|
if (syncTypes.Any() == false) return true;
|
||||||
|
var before = new Aop.SyncStructureBeforeEventArgs(entityTypes);
|
||||||
|
_orm.Aop.SyncStructureBefore?.Invoke(this, before);
|
||||||
|
Exception exception = null;
|
||||||
|
string ddl = null;
|
||||||
|
try {
|
||||||
lock (syncStructureLock) {
|
lock (syncStructureLock) {
|
||||||
var ddl = this.GetComparisonDDLStatements(syncTypes);
|
ddl = this.GetComparisonDDLStatements(syncTypes);
|
||||||
if (string.IsNullOrEmpty(ddl)) {
|
if (string.IsNullOrEmpty(ddl)) {
|
||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return true;
|
return true;
|
||||||
@ -266,6 +271,13 @@ namespace FreeSql.Sqlite {
|
|||||||
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true);
|
||||||
return affrows > 0;
|
return affrows > 0;
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
var after = new Aop.SyncStructureAfterEventArgs(before, ddl, exception);
|
||||||
|
_orm.Aop.SyncStructureAfter?.Invoke(this, after);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity) => _commonUtils.ConfigEntity(entity);
|
||||||
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
public ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) => _commonUtils.ConfigEntity(type, entity);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user