From 592247c0ac23ed6078f88fc407dcc11e03593b9b Mon Sep 17 00:00:00 2001 From: d4ilys <963922242@com> Date: Mon, 25 Nov 2024 14:13:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=B6=85=E7=BA=A7=E8=A1=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2/=E5=8F=82=E6=95=B0=E5=8C=96=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TDengineProvider.cs | 64 ++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/Providers/FreeSql.Provider.TDengine/TDengineProvider.cs b/Providers/FreeSql.Provider.TDengine/TDengineProvider.cs index fa4f2f183..2eeedae12 100644 --- a/Providers/FreeSql.Provider.TDengine/TDengineProvider.cs +++ b/Providers/FreeSql.Provider.TDengine/TDengineProvider.cs @@ -1,7 +1,13 @@ using FreeSql.Internal.CommonProvider; using System; using System.Data.Common; +using System.Linq; +using System.Reflection; +using System.Threading; +using FreeSql.Provider.TDengine.Attributes; using FreeSql.TDengine.Curd; +using Newtonsoft.Json.Linq; +using TDengine.Data.Client; namespace FreeSql.TDengine { @@ -10,7 +16,6 @@ namespace FreeSql.TDengine public TDengineProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) { - this.InternalCommonUtils = new TDengineUtils(this); this.InternalCommonExpression = new TDengineExpression(this.InternalCommonUtils); this.Ado = new TDengineAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, @@ -18,31 +23,74 @@ namespace FreeSql.TDengine this.Aop = new AopProvider(); this.DbFirst = new TDengineDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); this.CodeFirst = new TDengineCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); + + //处理超级表查询问题 + this.Aop.ConfigEntityProperty += (s, e) => + { + if (e.Property.ReflectedType == null) return; + + if (e.Property.ReflectedType.BaseType == null) return; + + var propertyInfo = e.Property.ReflectedType.BaseType.GetProperty(e.Property.Name); + + if (propertyInfo == null) return; + + if (propertyInfo.GetCustomAttribute(typeof(TDengineTagAttribute)) != null) + e.ModifyResult.IsIgnore = true; + }; + + //处理参数化 + this.Aop.CommandBefore += (_, e) => + { + if (e.Command.Parameters.Count <= 0) return; + var dengineParameters = new TDengineParameter[e.Command.Parameters.Count]; + e.Command.Parameters.CopyTo(dengineParameters, 0); + var cmdText = e.Command.CommandText; + var isChanged = false; + foreach (var parameter in dengineParameters.OrderByDescending(a => a.ParameterName.Length)) + { + var idx = cmdText.IndexOf(parameter.ParameterName, StringComparison.Ordinal); + if (idx != -1) + { + isChanged = true; + cmdText = + $"{cmdText.Substring(0, idx)}?{cmdText.Substring(idx + parameter.ParameterName.Length)}"; + } + } + + if (isChanged) e.Command.CommandText = cmdText; + }; } - public override ISelect CreateSelectProvider(object dywhere) => new TDengineSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); + public override ISelect CreateSelectProvider(object dywhere) => + new TDengineSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); + + public override IInsert CreateInsertProvider() => + new TDengineInsert(this, this.InternalCommonUtils, this.InternalCommonExpression); - public override IInsert CreateInsertProvider() => new TDengineInsert(this, this.InternalCommonUtils, this.InternalCommonExpression); - public override IUpdate CreateUpdateProvider(object dywhere) { - throw new NotImplementedException(); + throw new NotImplementedException($"FreeSql.Provider.TDengine {CoreStrings.S_Not_Implemented_Feature}"); } public override IDelete CreateDeleteProvider(object dywhere) { - throw new NotImplementedException(); + return new TDengineDelete(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); } public override IInsertOrUpdate CreateInsertOrUpdateProvider() { - throw new NotImplementedException(); + throw new NotImplementedException($"FreeSql.Provider.TDengine {CoreStrings.S_Not_Implemented_Feature}"); } + ~TDengineProvider() => this.Dispose(); + int _disposeCounter; + public override void Dispose() { - throw new NotImplementedException(); + if (Interlocked.Increment(ref _disposeCounter) != 1) return; + (this.Ado as AdoProvider)?.Dispose(); } } } \ No newline at end of file