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