├── icon.png ├── Npgsql.snk ├── global.json ├── src ├── EFCore.GaussDB │ ├── Properties │ │ ├── GaussDBStrings.Designer.tt │ │ └── AssemblyInfo.cs │ ├── Metadata │ │ ├── SortOrder.cs │ │ ├── NullSortOrder.cs │ │ ├── Conventions │ │ │ ├── GaussDBSharedTableConvention.cs │ │ │ ├── GaussDBJsonElementHackConvention.cs │ │ │ └── GaussDBPostgresModelFinalizingConvention.cs │ │ ├── Internal │ │ │ └── CockroachDbAnnotationNames.cs │ │ └── GaussDBValueGenerationStrategy.cs │ ├── Extensions │ │ ├── MethodInfoExtensions.cs │ │ ├── RelationalTypeMappingExtensions.cs │ │ ├── PropertyInfoExtensions.cs │ │ ├── VersionExtensions.cs │ │ ├── MemberInfoExtensions.cs │ │ ├── TypeExtensions.cs │ │ ├── GaussDBDatabaseModelExtensions.cs │ │ ├── GaussDBDatabaseFacadeExtensions.cs │ │ └── GaussDBMigrationBuilderExtensions.cs │ ├── Migrations │ │ └── Operations │ │ │ ├── GaussDBDropDatabaseOperation.cs │ │ │ └── GaussDBCreateDatabaseOperation.cs │ ├── Utilities │ │ ├── Util.cs │ │ ├── StringBuilderExtensions.cs │ │ └── SortOrderHelper.cs │ ├── Storage │ │ └── Internal │ │ │ ├── Mapping │ │ │ ├── IGaussDBTypeMapping.cs │ │ │ ├── GaussDBEStringTypeMapping.cs │ │ │ ├── GaussDBUIntTypeMapping.cs │ │ │ ├── GaussDBULongTypeMapping.cs │ │ │ ├── GaussDBTsRankingNormalizationTypeMapping.cs │ │ │ ├── GaussDBBoolTypeMapping.cs │ │ │ ├── GaussDBMoneyTypeMapping.cs │ │ │ ├── GaussDBRegconfigTypeMapping.cs │ │ │ ├── GaussDBRegdictionaryTypeMapping.cs │ │ │ ├── GaussDBRowValueTypeMapping.cs │ │ │ ├── GaussDBDoubleTypeMapping.cs │ │ │ ├── GaussDBFloatTypeMapping.cs │ │ │ ├── GaussDBTsQueryTypeMapping.cs │ │ │ └── GaussDBTsVectorMapping.cs │ │ │ ├── GaussDBTransientExceptionDetector.cs │ │ │ ├── IGaussDBRelationalConnection.cs │ │ │ ├── Json │ │ │ ├── JsonMacaddrReaderWriter.cs │ │ │ └── JsonBitArrayReaderWriter.cs │ │ │ └── GaussDBExecutionStrategyFactory.cs │ ├── ValueGeneration │ │ └── Internal │ │ │ ├── IGaussDBValueGeneratorCache.cs │ │ │ ├── IGaussDBSequenceValueGeneratorFactory.cs │ │ │ ├── GaussDBSequenceValueGeneratorState.cs │ │ │ ├── GaussDBValueGeneratorCache.cs │ │ │ ├── GaussDBSequenceHiLoValueGenerator.cs │ │ │ └── GaussDBSequenceValueGeneratorFactory.cs │ ├── Scaffolding │ │ └── Internal │ │ │ ├── DbDataReaderExtension.cs │ │ │ └── GaussDBCodeGenerator.cs │ ├── Internal │ │ └── IReadOnlyListExtensions.cs │ ├── EFCore.GaussDB.sln │ ├── Infrastructure │ │ └── Internal │ │ │ └── IGaussDBSingletonOptions.cs │ ├── README.md │ ├── Types │ │ └── GaussDBTsRankingNormalization.cs │ ├── Query │ │ ├── ExpressionTranslators │ │ │ └── Internal │ │ │ │ ├── GaussDBAggregateMethodCallTranslatorProvider.cs │ │ │ │ ├── GaussDBStringMemberTranslator.cs │ │ │ │ ├── GaussDBNewGuidTranslator.cs │ │ │ │ ├── GaussDBRandomTranslator.cs │ │ │ │ ├── GaussDBBigIntegerMemberTranslator.cs │ │ │ │ ├── GaussDBMemberTranslatorProvider.cs │ │ │ │ ├── GaussDBRegexIsMatchTranslator.cs │ │ │ │ ├── GaussDBConvertTranslator.cs │ │ │ │ └── GaussDBLikeTranslator.cs │ │ ├── Internal │ │ │ ├── GaussDBQueryCompilationContext.cs │ │ │ ├── GaussDBParameterBasedSqlProcessorFactory.cs │ │ │ ├── GaussDBQueryTranslationPostprocessorFactory.cs │ │ │ ├── GaussDBQuerySqlGeneratorFactory.cs │ │ │ ├── GaussDBQueryTranslationPostprocessor.cs │ │ │ ├── GaussDBSqlTranslatingExpressionVisitorFactory.cs │ │ │ ├── GaussDBQueryCompilationContextFactory.cs │ │ │ ├── GaussDBQueryTranslationPreprocessor.cs │ │ │ ├── GaussDBQueryRootProcessor.cs │ │ │ ├── GaussDBParameterBasedSqlProcessor.cs │ │ │ ├── GaussDBQueryTranslationPreprocessorFactory.cs │ │ │ ├── GaussDBCompiledQueryCacheKeyGenerator.cs │ │ │ └── GaussDBQueryableMethodTranslatingExpressionVisitorFactory.cs │ │ └── Expressions │ │ │ └── Internal │ │ │ ├── PgRegexMatchExpression.cs │ │ │ ├── PgUnknownBinaryExpression.cs │ │ │ ├── PgILikeExpression.cs │ │ │ └── PgDeleteExpression.cs │ ├── EFCore.GaussDB.csproj │ ├── Design │ │ └── Internal │ │ │ └── GaussDBDesignTimeServices.cs │ └── Update │ │ └── Internal │ │ ├── GaussDBModificationCommandFactory.cs │ │ └── GaussDBModificationCommandBatchFactory.cs ├── Directory.Build.props └── .editorconfig ├── .build ├── server.key └── server.crt ├── LICENSE ├── test └── Directory.Build.props ├── NuGet.config ├── Directory.Packages.props ├── README.md ├── EFCore.GaussDB.sln └── Directory.Build.props /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcore/EntityFrameworkCore.GaussDB/HEAD/icon.png -------------------------------------------------------------------------------- /Npgsql.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcore/EntityFrameworkCore.GaussDB/HEAD/Npgsql.snk -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.100-rc.2.23502.2", 4 | "rollForward": "latestMajor", 5 | "allowPrerelease": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Properties/GaussDBStrings.Designer.tt: -------------------------------------------------------------------------------- 1 | <# 2 | Session["ResourceFile"] = "GaussDBStrings.resx"; 3 | Session["LoggingDefinitionsClass"] = "Diagnostics.Internal.GaussDBLoggingDefinitions"; 4 | #> 5 | <#@ include file="..\..\..\tools\Resources.tt" #> 6 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Metadata/SortOrder.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; 2 | 3 | /// 4 | /// Options for modifying sort ordering of index values. 5 | /// 6 | public enum SortOrder 7 | { 8 | /// 9 | /// Specifies ascending sort order, which is the default. 10 | /// 11 | Ascending = 0, 12 | 13 | /// 14 | /// Specifies descending sort order. 15 | /// 16 | Descending = 1, 17 | } 18 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/MethodInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | 3 | namespace System.Reflection; 4 | 5 | [DebuggerStepThrough] 6 | internal static class MethodInfoExtensions 7 | { 8 | internal static bool IsClosedFormOf( 9 | this MethodInfo methodInfo, 10 | MethodInfo genericMethod) 11 | => methodInfo.IsGenericMethod 12 | && Equals( 13 | methodInfo.GetGenericMethodDefinition(), 14 | genericMethod); 15 | } 16 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | snupkg 7 | true 8 | enable 9 | nullablePublicOnly 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/RelationalTypeMappingExtensions.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace Microsoft.EntityFrameworkCore.Storage; 5 | 6 | internal static class RelationalTypeMappingExtensions 7 | { 8 | internal static string GenerateEmbeddedSqlLiteral(this RelationalTypeMapping mapping, object? value) 9 | => mapping is GaussDBTypeMapping GaussDBTypeMapping 10 | ? GaussDBTypeMapping.GenerateEmbeddedSqlLiteral(value) 11 | : mapping.GenerateSqlLiteral(value); 12 | } 13 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Migrations/Operations/GaussDBDropDatabaseOperation.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Migrations.Operations; 2 | 3 | /// 4 | /// A PostgreSQL-specific to drop a database. 5 | /// 6 | /// 7 | /// See Database migrations. 8 | /// 9 | public class GaussDBDropDatabaseOperation : MigrationOperation 10 | { 11 | /// 12 | /// The name of the database. 13 | /// 14 | public virtual string Name { get; set; } = null!; 15 | } 16 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/PropertyInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | 3 | namespace System.Reflection; 4 | 5 | [DebuggerStepThrough] 6 | internal static class PropertyInfoExtensions 7 | { 8 | public static bool IsStatic(this PropertyInfo property) 9 | => (property.GetMethod ?? property.SetMethod)!.IsStatic; 10 | 11 | public static bool IsIndexerProperty(this PropertyInfo propertyInfo) 12 | { 13 | var indexParams = propertyInfo.GetIndexParameters(); 14 | return indexParams.Length == 1 15 | && indexParams[0].ParameterType == typeof(string); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/VersionExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | 3 | namespace System; 4 | 5 | internal static class VersionExtensions 6 | { 7 | // Note: a null version is interpreted as the latest version and will always return true. 8 | internal static bool AtLeast(this Version? version, int major, int minor = 0) 9 | => version is null || version >= new Version(major, minor); 10 | 11 | // Note: a null version is interpreted as the latest version and will always return false. 12 | internal static bool IsUnder(this Version? version, int major, int minor = 0) 13 | => version is not null && version < new Version(major, minor); 14 | } 15 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Utilities/Util.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Utilities; 2 | 3 | internal static class Statics 4 | { 5 | internal static readonly bool[][] TrueArrays = 6 | { 7 | Array.Empty(), 8 | new[] { true }, 9 | new[] { true, true }, 10 | new[] { true, true, true }, 11 | new[] { true, true, true, true }, 12 | new[] { true, true, true, true, true }, 13 | new[] { true, true, true, true, true, true }, 14 | new[] { true, true, true, true, true, true, true }, 15 | new[] { true, true, true, true, true, true, true, true } 16 | }; 17 | 18 | internal static readonly bool[][] FalseArrays = { Array.Empty(), new[] { false }, new[] { false, false } }; 19 | } 20 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/IGaussDBTypeMapping.cs: -------------------------------------------------------------------------------- 1 | using GaussDBTypes; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public interface IGaussDBTypeMapping 12 | { 13 | /// 14 | /// The database type used by GaussDB. 15 | /// 16 | GaussDBDbType GaussDBDbType { get; } 17 | } 18 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/ValueGeneration/Internal/IGaussDBValueGeneratorCache.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.ValueGeneration.Internal; 2 | 3 | /// 4 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 5 | /// directly from your code. This API may change or be removed in future releases. 6 | /// 7 | public interface IGaussDBValueGeneratorCache : IValueGeneratorCache 8 | { 9 | /// 10 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 11 | /// directly from your code. This API may change or be removed in future releases. 12 | /// 13 | GaussDBSequenceValueGeneratorState GetOrAddSequenceState( 14 | IProperty property, 15 | IRelationalConnection connection); 16 | } 17 | -------------------------------------------------------------------------------- /.build/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXgIBAAKBgQDB3z87uFmxM66c7GtEQXsKzVFimOIR8KB9ZWebSYgVkc8w8SPc 3 | PACDdr5Z35xmj+vzp3Og6yomhdJIqk+IG7gxIt+94xtvT3DDsvSoFAcOd9f+kbGx 4 | PQrMXjKsMQbT18/l/DzA28BrDgDgpTJKLZBjN37I5l2t3zCBfmVKbXGlmwIDAQAB 5 | AoGBAJnspubCcivXzb33kx7JImisJP60RWFa/AEzPrQzCGGft7Gy8vbLiNjXsT/n 6 | 4uQnRn3YKFzN+VRGkXNyDN0SrQSrRrFST56aLBhqe4BEO3l6JQJQ6h1y5aW7/R+y 7 | ehV9HIQd+RFgcyejStXJnXYC7lPycOjT4SGG/7mOZkOIbRmJAkEA8NwHvvxsLW77 8 | UwVto7us0oR0Ey8/vCgbEruZTdr+rVeOKKUvM4K1r4hMunXc2kJ+hhYYMoF2wfIv 9 | gpPq1F+GLQJBAM4PFV8pL+fLqQqoRh/2dGDBKQU5wlQS+A4sTAPTdy3V1zx3BE8s 10 | KJeYIk2Z72HqNLAL/LUC/gwKwuVg+3k0v+cCQQC2HZhZxyDAZabwSi1xXMk6z924 11 | V8R4L1bxHhm3bXudc5NQlj2PVCiuFX/2iIG6IgbqubAIGC3ETauwrskjVSrtAkEA 12 | gltgddcki0t4IVnbIxVTAnKwdLHZkj591tmHLVR2LPT/OS1B+KRC+cQwz0729cao 13 | lka/E/RUq2GTcnEsJb2NOQJAOHwXsZJj+qrMQmHmmej6X2Rro4bX7cJmyK99mAtC 14 | LigiSdiY/uDqJ/p+cHPH9g2RLWeFetUAZID94uNRk1peAg== 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2021, Npgsql 2 | 3 | Permission to use, copy, modify, and distribute this software and its 4 | documentation for any purpose, without fee, and without a written agreement 5 | is hereby granted, provided that the above copyright notice and this 6 | paragraph and the following two paragraphs appear in all copies. 7 | 8 | IN NO EVENT SHALL NPGSQL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, 9 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, 10 | ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 11 | Npgsql HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | 13 | NPGSQL SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED 14 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 | PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND Npgsql 16 | HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, 17 | OR MODIFICATIONS. 18 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Metadata/NullSortOrder.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; 2 | 3 | /// 4 | /// Options for modifying sort ordering of NULL-values in indexes. 5 | /// 6 | public enum NullSortOrder 7 | { 8 | /// 9 | /// Represents an unspecified sort order. The database default will be used. 10 | /// 11 | Unspecified = 0, 12 | 13 | /// 14 | /// Specifies that nulls sort before non-nulls. 15 | /// 16 | /// 17 | /// This is the default when is specified. 18 | /// 19 | NullsFirst = 1, 20 | 21 | /// 22 | /// Specifies that nulls sort after non-nulls. 23 | /// 24 | /// 25 | /// This is the default when is not specified. 26 | /// 27 | NullsLast = 2, 28 | } 29 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Migrations/Operations/GaussDBCreateDatabaseOperation.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Migrations.Operations; 2 | 3 | /// 4 | /// A PostgreSQL-specific to create a database. 5 | /// 6 | /// 7 | /// See Database migrations. 8 | /// 9 | [DebuggerDisplay("CREATE DATABASE {Name}")] 10 | public class GaussDBCreateDatabaseOperation : DatabaseOperation 11 | { 12 | /// 13 | /// The name of the database. 14 | /// 15 | public virtual string Name { get; set; } = null!; 16 | 17 | /// 18 | /// The PostgreSQL database to use as a template for the new database to be created. 19 | /// 20 | public virtual string? Template { get; set; } 21 | 22 | /// 23 | /// The PostgreSQL tablespace in which to create the database. 24 | /// 25 | public virtual string? Tablespace { get; set; } 26 | } 27 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/ValueGeneration/Internal/IGaussDBSequenceValueGeneratorFactory.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.ValueGeneration.Internal; 4 | 5 | /// 6 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 7 | /// directly from your code. This API may change or be removed in future releases. 8 | /// 9 | public interface IGaussDBSequenceValueGeneratorFactory 10 | { 11 | /// 12 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 13 | /// directly from your code. This API may change or be removed in future releases. 14 | /// 15 | ValueGenerator Create( 16 | IProperty property, 17 | GaussDBSequenceValueGeneratorState generatorState, 18 | IGaussDBRelationalConnection connection, 19 | IRawSqlCommandBuilder rawSqlCommandBuilder, 20 | IRelationalCommandDiagnosticsLogger commandLogger); 21 | } 22 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Utilities/StringBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | 3 | namespace System.Text; 4 | 5 | internal static class StringBuilderExtensions 6 | { 7 | public static StringBuilder AppendJoin( 8 | this StringBuilder stringBuilder, 9 | IEnumerable values, 10 | string separator = ", ") 11 | => stringBuilder.AppendJoin(values, (sb, value) => sb.Append(value), separator); 12 | 13 | public static StringBuilder AppendJoin( 14 | this StringBuilder stringBuilder, 15 | IEnumerable values, 16 | Action joinAction, 17 | string separator) 18 | { 19 | var appended = false; 20 | 21 | foreach (var value in values) 22 | { 23 | joinAction(stringBuilder, value); 24 | stringBuilder.Append(separator); 25 | appended = true; 26 | } 27 | 28 | if (appended) 29 | { 30 | stringBuilder.Length -= separator.Length; 31 | } 32 | 33 | return stringBuilder; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Scaffolding/Internal/DbDataReaderExtension.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using System.Diagnostics.CodeAnalysis; 3 | 4 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal; 5 | 6 | internal static class DbDataReaderExtension 7 | { 8 | [DebuggerStepThrough] 9 | [return: MaybeNull] 10 | internal static T GetValueOrDefault(this DbDataReader reader, string name) 11 | { 12 | var idx = reader.GetOrdinal(name); 13 | return reader.IsDBNull(idx) 14 | ? default 15 | : reader.GetFieldValue(idx); 16 | } 17 | 18 | [DebuggerStepThrough] 19 | [return: MaybeNull] 20 | internal static T GetValueOrDefault(this DbDataRecord record, string name) 21 | { 22 | var idx = record.GetOrdinal(name); 23 | return record.IsDBNull(idx) 24 | ? default 25 | : (T)record.GetValue(idx); 26 | } 27 | 28 | [DebuggerStepThrough] 29 | internal static T GetFieldValue(this DbDataRecord record, string name) 30 | => (T)record.GetValue(record.GetOrdinal(name)); 31 | } 32 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Internal/IReadOnlyListExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Internal; 4 | 5 | internal static class IReadOnlyListExtensions 6 | { 7 | public static IReadOnlyList Slice(this IReadOnlyList list, int start) 8 | => new IReadOnlyListSlice(list, start); 9 | 10 | private sealed class IReadOnlyListSlice : IReadOnlyList 11 | { 12 | private readonly IReadOnlyList _underlying; 13 | private readonly int _start; 14 | 15 | internal IReadOnlyListSlice(IReadOnlyList underlying, int start) 16 | { 17 | _underlying = underlying; 18 | _start = start; 19 | } 20 | 21 | public IEnumerator GetEnumerator() 22 | => _underlying.Skip(_start).GetEnumerator(); 23 | 24 | IEnumerator IEnumerable.GetEnumerator() 25 | => GetEnumerator(); 26 | 27 | public int Count 28 | => _underlying.Count - _start; 29 | 30 | public T this[int index] 31 | => _underlying[_start + index]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/EFCore.GaussDB.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 17 3 | VisualStudioVersion = 17.5.2.0 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.GaussDB", "EFCore.GaussDB.csproj", "{924146F9-3761-F4BC-A4E0-FE7DACE64CE5}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Any CPU = Debug|Any CPU 10 | Release|Any CPU = Release|Any CPU 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {924146F9-3761-F4BC-A4E0-FE7DACE64CE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 14 | {924146F9-3761-F4BC-A4E0-FE7DACE64CE5}.Debug|Any CPU.Build.0 = Debug|Any CPU 15 | {924146F9-3761-F4BC-A4E0-FE7DACE64CE5}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | {924146F9-3761-F4BC-A4E0-FE7DACE64CE5}.Release|Any CPU.Build.0 = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(SolutionProperties) = preSolution 19 | HideSolutionNode = FALSE 20 | EndGlobalSection 21 | GlobalSection(ExtensibilityGlobals) = postSolution 22 | SolutionGuid = {60C36C95-C272-4C83-A7BD-FE20BF4DE337} 23 | EndGlobalSection 24 | EndGlobal 25 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/ValueGeneration/Internal/GaussDBSequenceValueGeneratorState.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.ValueGeneration.Internal; 2 | 3 | /// 4 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 5 | /// directly from your code. This API may change or be removed in future releases. 6 | /// 7 | public class GaussDBSequenceValueGeneratorState : HiLoValueGeneratorState 8 | { 9 | /// 10 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 11 | /// directly from your code. This API may change or be removed in future releases. 12 | /// 13 | public GaussDBSequenceValueGeneratorState(ISequence sequence) 14 | : base(Check.NotNull(sequence, nameof(sequence)).IncrementBy) 15 | { 16 | Sequence = sequence; 17 | } 18 | 19 | /// 20 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 21 | /// directly from your code. This API may change or be removed in future releases. 22 | /// 23 | public virtual ISequence Sequence { get; } 24 | } 25 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: DesignTimeProviderServices("GaussDB.EntityFrameworkCore.PostgreSQL.Design.Internal.GaussDBDesignTimeServices")] 4 | 5 | [assembly: 6 | InternalsVisibleTo( 7 | "GaussDB.EntityFrameworkCore.PostgreSQL.FunctionalTests, PublicKey=" 8 | + "0024000004800000940000000602000000240000525341310004000001000100" 9 | + "2b3c590b2a4e3d347e6878dc0ff4d21eb056a50420250c6617044330701d35c9" 10 | + "8078a5df97a62d83c9a2db2d072523a8fc491398254c6b89329b8c1dcef43a1e" 11 | + "7aa16153bcea2ae9a471145624826f60d7c8e71cd025b554a0177bd935a78096" 12 | + "29f0a7afc778ebb4ad033e1bf512c1a9c6ceea26b077bc46cac93800435e77ee")] 13 | 14 | [assembly: 15 | InternalsVisibleTo( 16 | "GaussDB.EntityFrameworkCore.PostgreSQL.Tests, PublicKey=" 17 | + "0024000004800000940000000602000000240000525341310004000001000100" 18 | + "2b3c590b2a4e3d347e6878dc0ff4d21eb056a50420250c6617044330701d35c9" 19 | + "8078a5df97a62d83c9a2db2d072523a8fc491398254c6b89329b8c1dcef43a1e" 20 | + "7aa16153bcea2ae9a471145624826f60d7c8e71cd025b554a0177bd935a78096" 21 | + "29f0a7afc778ebb4ad033e1bf512c1a9c6ceea26b077bc46cac93800435e77ee")] 22 | -------------------------------------------------------------------------------- /test/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net8.0 7 | false 8 | false 9 | 10 | 11 | $(NoWarn);xUnit1003;xUnit1004;xUnit1013;xUnit1024;EF1001 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/GaussDBTransientExceptionDetector.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBTransientExceptionDetector 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public static bool ShouldRetryOn(Exception? ex) 18 | => (ex as GaussDBException)?.IsTransient == true || ex is TimeoutException; 19 | } 20 | -------------------------------------------------------------------------------- /NuGet.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Utilities/SortOrderHelper.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Utilities; 4 | 5 | internal static class SortOrderHelper 6 | { 7 | public static bool IsDefaultNullSortOrder( 8 | IReadOnlyList? nullSortOrders, 9 | IReadOnlyList? isDescendingValues) 10 | { 11 | if (nullSortOrders is null) 12 | { 13 | return true; 14 | } 15 | 16 | for (var i = 0; i < nullSortOrders.Count; i++) 17 | { 18 | var nullSortOrder = nullSortOrders[i]; 19 | 20 | // We need to consider the ASC/DESC sort order to determine the default NULLS FIRST/LAST sort order. 21 | if (isDescendingValues is not null && (isDescendingValues.Count == 0 || isDescendingValues[i])) 22 | { 23 | // NULLS FIRST is the default when DESC is specified. 24 | if (nullSortOrder != NullSortOrder.NullsFirst) 25 | { 26 | return false; 27 | } 28 | } 29 | else 30 | { 31 | // NULLS LAST is the default when DESC is NOT specified. 32 | if (nullSortOrder != NullSortOrder.NullsLast) 33 | { 34 | return false; 35 | } 36 | } 37 | } 38 | 39 | return true; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Metadata/Conventions/GaussDBSharedTableConvention.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Metadata.Conventions; 4 | 5 | /// 6 | /// A convention that manipulates names of database objects for entity types that share a table to avoid clashes. 7 | /// 8 | public class GaussDBSharedTableConvention : SharedTableConvention 9 | { 10 | /// 11 | /// Creates a new instance of . 12 | /// 13 | /// Parameter object containing dependencies for this convention. 14 | /// Parameter object containing relational dependencies for this convention. 15 | public GaussDBSharedTableConvention( 16 | ProviderConventionSetBuilderDependencies dependencies, 17 | RelationalConventionSetBuilderDependencies relationalDependencies) 18 | : base(dependencies, relationalDependencies) 19 | { 20 | } 21 | 22 | /// 23 | protected override bool AreCompatible(IReadOnlyIndex index, IReadOnlyIndex duplicateIndex, in StoreObjectIdentifier storeObject) 24 | => base.AreCompatible(index, duplicateIndex, storeObject) 25 | && index.AreCompatibleForGaussDB(duplicateIndex, storeObject, shouldThrow: false); 26 | 27 | /// 28 | protected override bool CheckConstraintsUniqueAcrossTables 29 | => false; 30 | } 31 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Infrastructure/Internal/IGaussDBSingletonOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 4 | 5 | /// 6 | /// Represents options for GaussDB that can only be set at the singleton level. 7 | /// 8 | public interface IGaussDBSingletonOptions : ISingletonOptions 9 | { 10 | /// 11 | /// The backend version to target. 12 | /// 13 | Version PostgresVersion { get; } 14 | 15 | /// 16 | /// Whether the user has explicitly set the backend version to target. 17 | /// 18 | bool IsPostgresVersionSet { get; } 19 | 20 | /// 21 | /// Whether to target Redshift. 22 | /// 23 | bool UseRedshift { get; } 24 | 25 | /// 26 | /// Whether reverse null ordering is enabled. 27 | /// 28 | bool ReverseNullOrderingEnabled { get; } 29 | 30 | /// 31 | /// The data source being used, or if a connection string or connection was provided directly. 32 | /// 33 | DbDataSource? DataSource { get; } 34 | 35 | /// 36 | /// The collection of range mappings. 37 | /// 38 | IReadOnlyList UserRangeDefinitions { get; } 39 | 40 | /// 41 | /// The root service provider for the application, if available. />. 42 | /// 43 | IServiceProvider? ApplicationServiceProvider { get; } 44 | } 45 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/README.md: -------------------------------------------------------------------------------- 1 | # GaussDB Entity Framework Core provider for PostgreSQL 2 | 3 | DotNetCore.EntityFrameworkCore.GaussDB is the open source EF Core provider for PostgreSQL. It allows you to interact with PostgreSQL via the most widely-used .NET O/RM from Microsoft, and use familiar LINQ syntax to express queries. It's built on top of [DotNetCore.GaussDB](https://github.com/dotnetcore/DotNetCore.GaussDB). 4 | 5 | The provider looks and feels just like any other Entity Framework Core provider. Here's a quick sample to get you started: 6 | 7 | ```csharp 8 | await using var ctx = new BlogContext(); 9 | await ctx.Database.EnsureDeletedAsync(); 10 | await ctx.Database.EnsureCreatedAsync(); 11 | 12 | // Insert a Blog 13 | ctx.Blogs.Add(new() { Name = "FooBlog" }); 14 | await ctx.SaveChangesAsync(); 15 | 16 | // Query all blogs who's name starts with F 17 | var fBlogs = await ctx.Blogs.Where(b => b.Name.StartsWith("F")).ToListAsync(); 18 | 19 | public class BlogContext : DbContext 20 | { 21 | public DbSet Blogs { get; set; } 22 | 23 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 24 | => optionsBuilder.UseGaussDB(@"host={host};port={port};username={username};password={password};database={database}"); 25 | } 26 | 27 | public class Blog 28 | { 29 | public int Id { get; set; } 30 | public string Name { get; set; } 31 | } 32 | ``` 33 | 34 | Aside from providing general EF Core support for GaussDB, the provider also exposes some GaussDB-specific capabilities, allowing you to query JSON, array or range columns, as well as many other advanced features. For more information. For information about EF Core in general, see the [EF Core website](https://docs.microsoft.com/ef/core/). 35 | 36 | -------------------------------------------------------------------------------- /Directory.Packages.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8.0.0 4 | 8.0.0 5 | 8.0.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Metadata/Conventions/GaussDBJsonElementHackConvention.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 3 | 4 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Metadata.Conventions; 5 | 6 | /// 7 | /// This convention is a hack around https://github.com/dotnet/efcore/issues/32192. To support the EF owned entity JSON support, EF 8 | /// requires 9 | /// that a lookup of the CLR type return the provider's special . But GaussDB has 10 | /// its own JSON DOM support, where actually mapping is allowed as a weakly-typed mapping strategy. The two 11 | /// JSON type mappings are incompatible notably because EF's is expected to return UTF8 byte data which is 12 | /// then parsed via (and not a string). So for properties actually typed as , we 13 | /// hack here and set the type mapping rather than going through the regular type mapping process. 14 | /// 15 | public class GaussDBJsonElementHackConvention : IPropertyAddedConvention 16 | { 17 | private GaussDBJsonTypeMapping? _jsonTypeMapping; 18 | 19 | /// 20 | public void ProcessPropertyAdded(IConventionPropertyBuilder propertyBuilder, IConventionContext context) 21 | { 22 | var property = propertyBuilder.Metadata; 23 | 24 | if (property.ClrType == typeof(JsonElement) && property.GetColumnType() is null) 25 | { 26 | property.SetTypeMapping(_jsonTypeMapping ??= new GaussDBJsonTypeMapping("jsonb", typeof(JsonElement))); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/MemberInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | 3 | namespace System.Reflection; 4 | 5 | internal static class EntityFrameworkMemberInfoExtensions 6 | { 7 | public static Type GetMemberType(this MemberInfo memberInfo) 8 | => (memberInfo as PropertyInfo)?.PropertyType ?? ((FieldInfo)memberInfo).FieldType; 9 | 10 | public static bool IsSameAs(this MemberInfo? propertyInfo, MemberInfo? otherPropertyInfo) 11 | => propertyInfo is null 12 | ? otherPropertyInfo is null 13 | : (otherPropertyInfo is not null 14 | && (Equals(propertyInfo, otherPropertyInfo) 15 | || (propertyInfo.Name == otherPropertyInfo.Name 16 | && propertyInfo.DeclaringType is not null 17 | && otherPropertyInfo.DeclaringType is not null 18 | && (propertyInfo.DeclaringType == otherPropertyInfo.DeclaringType 19 | || propertyInfo.DeclaringType.GetTypeInfo().IsSubclassOf(otherPropertyInfo.DeclaringType) 20 | || otherPropertyInfo.DeclaringType.GetTypeInfo().IsSubclassOf(propertyInfo.DeclaringType) 21 | || propertyInfo.DeclaringType.GetTypeInfo().ImplementedInterfaces.Contains(otherPropertyInfo.DeclaringType) 22 | || otherPropertyInfo.DeclaringType.GetTypeInfo().ImplementedInterfaces 23 | .Contains(propertyInfo.DeclaringType))))); 24 | 25 | public static string GetSimpleMemberName(this MemberInfo member) 26 | { 27 | var name = member.Name; 28 | var index = name.LastIndexOf('.'); 29 | return index >= 0 ? name.Substring(index + 1) : name; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/IGaussDBRelationalConnection.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public interface IGaussDBRelationalConnection : IRelationalConnection 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | IGaussDBRelationalConnection CreateAdminConnection(); 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | GaussDBRelationalConnection CloneWith(string connectionString); 26 | } 27 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Metadata/Internal/CockroachDbAnnotationNames.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Metadata.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public static class CockroachDbAnnotationNames 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public const string Prefix = GaussDBAnnotationNames.Prefix + "CockroachDB:"; 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public const string InterleaveInParent = Prefix + "InterleaveInParent"; 26 | } 27 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Json/JsonMacaddrReaderWriter.cs: -------------------------------------------------------------------------------- 1 | using System.Net.NetworkInformation; 2 | using System.Text.Json; 3 | using Microsoft.EntityFrameworkCore.Storage.Json; 4 | 5 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Json; 6 | 7 | /// 8 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 9 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 10 | /// any release. You should only use it directly in your code with extreme caution and knowing that 11 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 12 | /// 13 | public sealed class JsonMacaddrReaderWriter : JsonValueReaderWriter 14 | { 15 | /// 16 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 17 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 18 | /// any release. You should only use it directly in your code with extreme caution and knowing that 19 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 20 | /// 21 | public static JsonMacaddrReaderWriter Instance { get; } = new(); 22 | 23 | private JsonMacaddrReaderWriter() 24 | { 25 | } 26 | 27 | /// 28 | public override PhysicalAddress FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null) 29 | => PhysicalAddress.Parse(manager.CurrentReader.GetString()!); 30 | 31 | /// 32 | public override void ToJsonTyped(Utf8JsonWriter writer, PhysicalAddress value) 33 | => writer.WriteStringValue(value.ToString()); 34 | } 35 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Types/GaussDBTsRankingNormalization.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace Microsoft.EntityFrameworkCore; 5 | 6 | /// 7 | /// Specifies whether and how a document's length should impact its rank. 8 | /// This is used with the ranking functions in . 9 | /// See http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING 10 | /// for more information about the behaviors that are controlled by this value. 11 | /// 12 | [Flags] 13 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 14 | public enum GaussDBTsRankingNormalization 15 | { 16 | /// 17 | /// Ignores the document length. 18 | /// 19 | Default = 0, 20 | 21 | /// 22 | /// Divides the rank by 1 + the logarithm of the document length. 23 | /// 24 | DivideBy1PlusLogLength = 1, 25 | 26 | /// 27 | /// Divides the rank by the document length. 28 | /// 29 | DivideByLength = 2, 30 | 31 | /// 32 | /// Divides the rank by the mean harmonic distance between extents (this is implemented only by ts_rank_cd). 33 | /// 34 | DivideByMeanHarmonicDistanceBetweenExtents = 4, 35 | 36 | /// 37 | /// Divides the rank by the number of unique words in document. 38 | /// 39 | DivideByUniqueWordCount = 8, 40 | 41 | /// 42 | /// Divides the rank by 1 + the logarithm of the number of unique words in document. 43 | /// 44 | DividesBy1PlusLogUniqueWordCount = 16, 45 | 46 | /// 47 | /// Divides the rank by itself + 1. 48 | /// 49 | DivideByItselfPlusOne = 32 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GaussDB Entity Framework Core provider for PostgreSQL 2 | 3 | [![Member project of .NET Core Community](https://img.shields.io/badge/member%20project%20of-NCC-9e20c9.svg)](https://github.com/dotnetcore) 4 | [![nuget](https://img.shields.io/nuget/v/DotNetCore.EntityFrameworkCore.GaussDB.svg?style=flat-square)](https://www.nuget.org/packages/DotNetCore.EntityFrameworkCore.GaussDB) 5 | [![stats](https://img.shields.io/nuget/dt/DotNetCore.EntityFrameworkCore.GaussDB.svg?style=flat-square)](https://www.nuget.org/stats/packages/DotNetCore.EntityFrameworkCore.GaussDB?groupby=Version) 6 | 7 | 8 | DotNetCore.EntityFrameworkCore.GaussDB is the open source EF Core provider for PostgreSQL. It allows you to interact with PostgreSQL via the most widely-used .NET O/RM from Microsoft, and use familiar LINQ syntax to express queries. It's built on top of [DotNetCore.GaussDB](https://github.com/dotnetcore/DotNetCore.GaussDB). 9 | 10 | The provider looks and feels just like any other Entity Framework Core provider. Here's a quick sample to get you started: 11 | 12 | ```csharp 13 | await using var ctx = new BlogContext(); 14 | await ctx.Database.EnsureDeletedAsync(); 15 | await ctx.Database.EnsureCreatedAsync(); 16 | 17 | // Insert a Blog 18 | ctx.Blogs.Add(new() { Name = "FooBlog" }); 19 | await ctx.SaveChangesAsync(); 20 | 21 | // Query all blogs who's name starts with F 22 | var fBlogs = await ctx.Blogs.Where(b => b.Name.StartsWith("F")).ToListAsync(); 23 | 24 | public class BlogContext : DbContext 25 | { 26 | public DbSet Blogs { get; set; } 27 | 28 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 29 | => optionsBuilder.UseGaussDB(@"host={host};port={port};username={username};password={password};database={database}"); 30 | } 31 | 32 | public class Blog 33 | { 34 | public int Id { get; set; } 35 | public string Name { get; set; } 36 | } 37 | ``` 38 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Scaffolding/Internal/GaussDBCodeGenerator.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal; 4 | 5 | /// 6 | /// The default code generator for GaussDB. 7 | /// 8 | public class GaussDBCodeGenerator : ProviderCodeGenerator 9 | { 10 | private static readonly MethodInfo _useGaussDBMethodInfo 11 | = typeof(GaussDBDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod( 12 | nameof(GaussDBDbContextOptionsBuilderExtensions.UseGaussDB), 13 | typeof(DbContextOptionsBuilder), 14 | typeof(string), 15 | typeof(Action)); 16 | 17 | /// 18 | /// Constructs an instance of the class. 19 | /// 20 | /// The dependencies. 21 | public GaussDBCodeGenerator(ProviderCodeGeneratorDependencies dependencies) 22 | : base(dependencies) 23 | { 24 | } 25 | 26 | /// 27 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 28 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 29 | /// any release. You should only use it directly in your code with extreme caution and knowing that 30 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 31 | /// 32 | public override MethodCallCodeFragment GenerateUseProvider( 33 | string connectionString, 34 | MethodCallCodeFragment? providerOptions) 35 | => new( 36 | _useGaussDBMethodInfo, 37 | providerOptions is null 38 | ? new object[] { connectionString } 39 | : new object[] { connectionString, new NestedClosureCodeFragment("x", providerOptions) }); 40 | } 41 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/GaussDBExecutionStrategyFactory.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBExecutionStrategyFactory : RelationalExecutionStrategyFactory 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public GaussDBExecutionStrategyFactory( 18 | ExecutionStrategyDependencies dependencies) 19 | : base(dependencies) 20 | { 21 | } 22 | 23 | /// 24 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 25 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 26 | /// any release. You should only use it directly in your code with extreme caution and knowing that 27 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 28 | /// 29 | protected override IExecutionStrategy CreateDefaultStrategy(ExecutionStrategyDependencies dependencies) 30 | => new GaussDBExecutionStrategy(dependencies); 31 | } 32 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBAggregateMethodCallTranslatorProvider.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBAggregateMethodCallTranslatorProvider : RelationalAggregateMethodCallTranslatorProvider 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public GaussDBAggregateMethodCallTranslatorProvider( 18 | RelationalAggregateMethodCallTranslatorProviderDependencies dependencies, 19 | IModel model) 20 | : base(dependencies) 21 | { 22 | var sqlExpressionFactory = (GaussDBSqlExpressionFactory)dependencies.SqlExpressionFactory; 23 | var typeMappingSource = dependencies.RelationalTypeMappingSource; 24 | 25 | AddTranslators( 26 | new IAggregateMethodCallTranslator[] 27 | { 28 | new GaussDBQueryableAggregateMethodTranslator(sqlExpressionFactory, typeMappingSource), 29 | new GaussDBStatisticsAggregateMethodTranslator(sqlExpressionFactory, typeMappingSource), 30 | new GaussDBMiscAggregateMethodTranslator(sqlExpressionFactory, typeMappingSource, model) 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/EFCore.GaussDB.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | DotNetCore.EntityFrameworkCore.GaussDB 6 | DotNetCore.EntityFrameworkCore.GaussDB 7 | DotNetCore.EntityFrameworkCore.GaussDB 8 | 9 | NCC;Jeffcky 10 | PostgreSQL/GaussDB provider for Entity Framework Core. 11 | gaussdb;Entity Framework Core;entity-framework-core;ef;efcore;orm;sql 12 | README.md 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | TextTemplatingFileGenerator 32 | GaussDBStrings.Designer.cs 33 | 34 | 35 | 36 | TextTemplatingFileGenerator 37 | 38 | 39 | 40 | GaussDB.EntityFrameworkCore.PostgreSQL.Internal 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQueryCompilationContext.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBQueryCompilationContext : RelationalQueryCompilationContext 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public GaussDBQueryCompilationContext( 18 | QueryCompilationContextDependencies dependencies, 19 | RelationalQueryCompilationContextDependencies relationalDependencies, 20 | bool async) 21 | : base(dependencies, relationalDependencies, async) 22 | { 23 | } 24 | 25 | /// 26 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 27 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 28 | /// any release. You should only use it directly in your code with extreme caution and knowing that 29 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 30 | /// 31 | public override bool IsBuffering 32 | => base.IsBuffering || QuerySplittingBehavior == Microsoft.EntityFrameworkCore.QuerySplittingBehavior.SplitQuery; 33 | } 34 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Design/Internal/GaussDBDesignTimeServices.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Design.Internal; 2 | using GaussDB.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal; 3 | 4 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Design.Internal; 5 | 6 | /// 7 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 8 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 9 | /// any release. You should only use it directly in your code with extreme caution and knowing that 10 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 11 | /// 12 | public class GaussDBDesignTimeServices : IDesignTimeServices 13 | { 14 | /// 15 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 16 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 17 | /// any release. You should only use it directly in your code with extreme caution and knowing that 18 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 19 | /// 20 | public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollection) 21 | { 22 | Check.NotNull(serviceCollection, nameof(serviceCollection)); 23 | 24 | serviceCollection.AddEntityFrameworkGaussDB(); 25 | #pragma warning disable EF1001 // Internal EF Core API usage. 26 | new EntityFrameworkRelationalDesignServicesBuilder(serviceCollection) 27 | .TryAdd() 28 | #pragma warning restore EF1001 // Internal EF Core API usage. 29 | .TryAdd() 30 | .TryAdd() 31 | .TryAdd() 32 | .TryAddCoreServices(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Update/Internal/GaussDBModificationCommandFactory.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Update.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBModificationCommandFactory : IModificationCommandFactory 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public virtual IModificationCommand CreateModificationCommand( 18 | in ModificationCommandParameters modificationCommandParameters) 19 | => new GaussDBModificationCommand(modificationCommandParameters); 20 | 21 | /// 22 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 23 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 24 | /// any release. You should only use it directly in your code with extreme caution and knowing that 25 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 26 | /// 27 | public virtual INonTrackedModificationCommand CreateNonTrackedModificationCommand( 28 | in NonTrackedModificationCommandParameters modificationCommandParameters) 29 | => new GaussDBModificationCommand(modificationCommandParameters); 30 | } 31 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace System.Reflection; 6 | 7 | internal static class TypeExtensions 8 | { 9 | internal static bool IsGenericList(this Type? type) 10 | => type is not null && type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>); 11 | 12 | internal static bool IsArrayOrGenericList(this Type type) 13 | => type.IsArray || type.IsGenericList(); 14 | 15 | internal static bool TryGetElementType(this Type type, [NotNullWhen(true)] out Type? elementType) 16 | { 17 | elementType = type.IsArray 18 | ? type.GetElementType() 19 | : type.IsGenericList() 20 | ? type.GetGenericArguments()[0] 21 | : null; 22 | return elementType is not null; 23 | } 24 | 25 | internal static bool IsRange(this SqlExpression expression) 26 | => expression.TypeMapping is GaussDBRangeTypeMapping || expression.Type.IsRange(); 27 | 28 | internal static bool IsRange(this Type type) 29 | => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(GaussDBRange<>) 30 | || type is { Name: "Interval" or "DateInterval", Namespace: "NodaTime" }; 31 | 32 | internal static bool IsMultirange(this SqlExpression expression) 33 | => expression.TypeMapping is GaussDBMultirangeTypeMapping 34 | || expression.Type.IsMultirange(); 35 | 36 | internal static bool IsMultirange(this Type type) 37 | => type.TryGetElementType(out var elementType) && elementType.IsRange(); 38 | 39 | public static PropertyInfo? FindIndexerProperty(this Type type) 40 | { 41 | var defaultPropertyAttribute = type.GetCustomAttributes().FirstOrDefault(); 42 | 43 | return defaultPropertyAttribute is null 44 | ? null 45 | : type.GetRuntimeProperties() 46 | .FirstOrDefault(pi => pi.Name == defaultPropertyAttribute.MemberName && pi.GetIndexParameters().Length == 1); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBParameterBasedSqlProcessorFactory.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBParameterBasedSqlProcessorFactory : IRelationalParameterBasedSqlProcessorFactory 10 | { 11 | private readonly RelationalParameterBasedSqlProcessorDependencies _dependencies; 12 | 13 | /// 14 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 15 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 16 | /// any release. You should only use it directly in your code with extreme caution and knowing that 17 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 18 | /// 19 | public GaussDBParameterBasedSqlProcessorFactory( 20 | RelationalParameterBasedSqlProcessorDependencies dependencies) 21 | { 22 | _dependencies = dependencies; 23 | } 24 | 25 | /// 26 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 27 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 28 | /// any release. You should only use it directly in your code with extreme caution and knowing that 29 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 30 | /// 31 | public virtual RelationalParameterBasedSqlProcessor Create(bool useRelationalNulls) 32 | => new GaussDBParameterBasedSqlProcessor(_dependencies, useRelationalNulls); 33 | } 34 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQueryTranslationPostprocessorFactory.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBQueryTranslationPostprocessorFactory : IQueryTranslationPostprocessorFactory 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public GaussDBQueryTranslationPostprocessorFactory( 18 | QueryTranslationPostprocessorDependencies dependencies, 19 | RelationalQueryTranslationPostprocessorDependencies relationalDependencies) 20 | { 21 | Dependencies = dependencies; 22 | RelationalDependencies = relationalDependencies; 23 | } 24 | 25 | /// 26 | /// Dependencies for this service. 27 | /// 28 | protected virtual QueryTranslationPostprocessorDependencies Dependencies { get; } 29 | 30 | /// 31 | /// Relational provider-specific dependencies for this service. 32 | /// 33 | protected virtual RelationalQueryTranslationPostprocessorDependencies RelationalDependencies { get; } 34 | 35 | /// 36 | public virtual QueryTranslationPostprocessor Create(QueryCompilationContext queryCompilationContext) 37 | => new GaussDBQueryTranslationPostprocessor(Dependencies, RelationalDependencies, queryCompilationContext); 38 | } 39 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/ValueGeneration/Internal/GaussDBValueGeneratorCache.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.ValueGeneration.Internal; 4 | 5 | /// 6 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 7 | /// directly from your code. This API may change or be removed in future releases. 8 | /// 9 | public class GaussDBValueGeneratorCache : ValueGeneratorCache, IGaussDBValueGeneratorCache 10 | { 11 | private readonly ConcurrentDictionary _sequenceGeneratorCache 12 | = new(); 13 | 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// Parameter object containing dependencies for this service. 18 | public GaussDBValueGeneratorCache(ValueGeneratorCacheDependencies dependencies) 19 | : base(dependencies) 20 | { 21 | } 22 | 23 | /// 24 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 25 | /// directly from your code. This API may change or be removed in future releases. 26 | /// 27 | public virtual GaussDBSequenceValueGeneratorState GetOrAddSequenceState( 28 | IProperty property, 29 | IRelationalConnection connection) 30 | { 31 | var sequence = property.FindHiLoSequence(); 32 | 33 | Debug.Assert(sequence is not null); 34 | 35 | return _sequenceGeneratorCache.GetOrAdd( 36 | GetSequenceName(sequence, connection), 37 | _ => new GaussDBSequenceValueGeneratorState(sequence)); 38 | } 39 | 40 | private static string GetSequenceName(ISequence sequence, IRelationalConnection connection) 41 | { 42 | var dbConnection = connection.DbConnection; 43 | 44 | return dbConnection.Database.ToUpperInvariant() 45 | + "::" 46 | + dbConnection.DataSource.ToUpperInvariant() 47 | + "::" 48 | + (sequence.Schema is null ? "" : sequence.Schema + ".") 49 | + sequence.Name; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQuerySqlGeneratorFactory.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 4 | 5 | /// 6 | /// The default factory for GaussDB-specific query SQL generators. 7 | /// 8 | public class GaussDBQuerySqlGeneratorFactory : IQuerySqlGeneratorFactory 9 | { 10 | private readonly QuerySqlGeneratorDependencies _dependencies; 11 | private readonly IRelationalTypeMappingSource _typeMappingSource; 12 | private readonly IGaussDBSingletonOptions _GaussDBSingletonOptions; 13 | 14 | /// 15 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 16 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 17 | /// any release. You should only use it directly in your code with extreme caution and knowing that 18 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 19 | /// 20 | public GaussDBQuerySqlGeneratorFactory( 21 | QuerySqlGeneratorDependencies dependencies, 22 | IRelationalTypeMappingSource typeMappingSource, 23 | IGaussDBSingletonOptions GaussDBSingletonOptions) 24 | { 25 | _dependencies = dependencies; 26 | _typeMappingSource = typeMappingSource; 27 | _GaussDBSingletonOptions = GaussDBSingletonOptions; 28 | } 29 | 30 | /// 31 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 32 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 33 | /// any release. You should only use it directly in your code with extreme caution and knowing that 34 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 35 | /// 36 | public virtual QuerySqlGenerator Create() 37 | => new GaussDBQuerySqlGenerator( 38 | _dependencies, 39 | _typeMappingSource, 40 | _GaussDBSingletonOptions.ReverseNullOrderingEnabled, 41 | _GaussDBSingletonOptions.PostgresVersion); 42 | } 43 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBStringMemberTranslator.cs: -------------------------------------------------------------------------------- 1 | using static GaussDB.EntityFrameworkCore.PostgreSQL.Utilities.Statics; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 4 | 5 | /// 6 | /// Translates to 'length(text)'. 7 | /// 8 | public class GaussDBStringMemberTranslator : IMemberTranslator 9 | { 10 | private readonly ISqlExpressionFactory _sqlExpressionFactory; 11 | 12 | /// 13 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 14 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 15 | /// any release. You should only use it directly in your code with extreme caution and knowing that 16 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 17 | /// 18 | public GaussDBStringMemberTranslator(ISqlExpressionFactory sqlExpressionFactory) 19 | { 20 | _sqlExpressionFactory = sqlExpressionFactory; 21 | } 22 | 23 | /// 24 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 25 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 26 | /// any release. You should only use it directly in your code with extreme caution and knowing that 27 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 28 | /// 29 | public virtual SqlExpression? Translate( 30 | SqlExpression? instance, 31 | MemberInfo member, 32 | Type returnType, 33 | IDiagnosticsLogger logger) 34 | => member.Name == nameof(string.Length) && instance?.Type == typeof(string) 35 | ? _sqlExpressionFactory.Convert( 36 | _sqlExpressionFactory.Function( 37 | "length", 38 | new[] { instance }, 39 | nullable: true, 40 | argumentsPropagateNullability: TrueArrays[1], 41 | typeof(long)), 42 | returnType) 43 | : null; 44 | } 45 | -------------------------------------------------------------------------------- /src/.editorconfig: -------------------------------------------------------------------------------- 1 | # Code analysis rules and configuration 2 | 3 | root = false 4 | 5 | # Code files 6 | [*.cs] 7 | 8 | # Design rules 9 | 10 | # CA1001: Types that own disposable fields should be disposable 11 | dotnet_diagnostic.CA1001.severity = error 12 | 13 | # Globalization rules 14 | 15 | # CA1303: Do not pass literals as localized parameters 16 | dotnet_diagnostic.CA1303.severity = none 17 | 18 | # CA1304: Specify CultureInfo 19 | dotnet_diagnostic.CA1304.severity = error 20 | 21 | # CA1305: Specify IFormatProvider 22 | dotnet_diagnostic.CA1305.severity = none 23 | 24 | # CA1307: Specify StringComparison for clarity 25 | dotnet_diagnostic.CA1307.severity = none 26 | 27 | # CA1308: Normalize strings to uppercase 28 | dotnet_diagnostic.CA1308.severity = none 29 | 30 | # CA1309: Use ordinal stringcomparison 31 | dotnet_diagnostic.CA1309.severity = error 32 | 33 | # CA1310: Specify StringComparison for correctness 34 | dotnet_diagnostic.CA1310.severity = error 35 | 36 | # CA2101: Specify marshaling for P/Invoke string arguments 37 | dotnet_diagnostic.CA2101.severity = error 38 | 39 | # Reliability Rules 40 | 41 | # CA2000: Dispose objects before losing scope 42 | # Not reliable enough - false positives 43 | dotnet_diagnostic.CA2000.severity = suggestion 44 | 45 | # CA2002: Do not lock on objects with weak identity 46 | dotnet_diagnostic.CA2002.severity = error 47 | 48 | # CA2007: Consider calling ConfigureAwait on the awaited task 49 | dotnet_diagnostic.CA2007.severity = error 50 | 51 | # CA2008: Do not create tasks without passing a TaskScheduler 52 | dotnet_diagnostic.CA2008.severity = error 53 | 54 | # CA2009: Do not call ToImmutableCollection on an ImmutableCollection value 55 | dotnet_diagnostic.CA2009.severity = error 56 | 57 | # CA2011: Avoid infinite recursion 58 | dotnet_diagnostic.CA2011.severity = error 59 | 60 | # CA2012: Use ValueTasks correctly 61 | dotnet_diagnostic.CA2012.severity = error 62 | 63 | # CA2013: Do not use ReferenceEquals with value types 64 | dotnet_diagnostic.CA2013.severity = error 65 | 66 | # CA2014: Do not use stackalloc in loops 67 | dotnet_diagnostic.CA2014.severity = error 68 | 69 | # CA2015: Do not define finalizers for types derived from MemoryManager 70 | dotnet_diagnostic.CA2015.severity = error 71 | 72 | # CA2016: Forward the 'CancellationToken' parameter to methods that take one 73 | dotnet_diagnostic.CA2016.severity = error 74 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQueryTranslationPostprocessor.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBQueryTranslationPostprocessor : RelationalQueryTranslationPostprocessor 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public GaussDBQueryTranslationPostprocessor( 18 | QueryTranslationPostprocessorDependencies dependencies, 19 | RelationalQueryTranslationPostprocessorDependencies relationalDependencies, 20 | QueryCompilationContext queryCompilationContext) 21 | : base(dependencies, relationalDependencies, queryCompilationContext) 22 | { 23 | } 24 | 25 | /// 26 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 27 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 28 | /// any release. You should only use it directly in your code with extreme caution and knowing that 29 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 30 | /// 31 | public override Expression Process(Expression query) 32 | { 33 | var result = base.Process(query); 34 | 35 | result = new GaussDBUnnestPostprocessor().Visit(result); 36 | result = new GaussDBSetOperationTypeResolutionCompensatingExpressionVisitor().Visit(result); 37 | 38 | return result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBSqlTranslatingExpressionVisitorFactory.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBSqlTranslatingExpressionVisitorFactory : IRelationalSqlTranslatingExpressionVisitorFactory 10 | { 11 | private readonly RelationalSqlTranslatingExpressionVisitorDependencies _dependencies; 12 | 13 | /// 14 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 15 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 16 | /// any release. You should only use it directly in your code with extreme caution and knowing that 17 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 18 | /// 19 | public GaussDBSqlTranslatingExpressionVisitorFactory( 20 | RelationalSqlTranslatingExpressionVisitorDependencies dependencies) 21 | { 22 | _dependencies = dependencies; 23 | } 24 | 25 | /// 26 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 27 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 28 | /// any release. You should only use it directly in your code with extreme caution and knowing that 29 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 30 | /// 31 | public virtual RelationalSqlTranslatingExpressionVisitor Create( 32 | QueryCompilationContext queryCompilationContext, 33 | QueryableMethodTranslatingExpressionVisitor queryableMethodTranslatingExpressionVisitor) 34 | => new GaussDBSqlTranslatingExpressionVisitor( 35 | _dependencies, 36 | queryCompilationContext, 37 | queryableMethodTranslatingExpressionVisitor); 38 | } 39 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQueryCompilationContextFactory.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBQueryCompilationContextFactory : IQueryCompilationContextFactory 10 | { 11 | private readonly QueryCompilationContextDependencies _dependencies; 12 | private readonly RelationalQueryCompilationContextDependencies _relationalDependencies; 13 | 14 | /// 15 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 16 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 17 | /// any release. You should only use it directly in your code with extreme caution and knowing that 18 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 19 | /// 20 | public GaussDBQueryCompilationContextFactory( 21 | QueryCompilationContextDependencies dependencies, 22 | RelationalQueryCompilationContextDependencies relationalDependencies) 23 | { 24 | Check.NotNull(dependencies, nameof(dependencies)); 25 | Check.NotNull(relationalDependencies, nameof(relationalDependencies)); 26 | 27 | _dependencies = dependencies; 28 | _relationalDependencies = relationalDependencies; 29 | } 30 | 31 | /// 32 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 33 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 34 | /// any release. You should only use it directly in your code with extreme caution and knowing that 35 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 36 | /// 37 | public virtual QueryCompilationContext Create(bool async) 38 | => new GaussDBQueryCompilationContext(_dependencies, _relationalDependencies, async); 39 | } 40 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Json/JsonBitArrayReaderWriter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Text.Json; 3 | using Microsoft.EntityFrameworkCore.Storage.Json; 4 | 5 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Json; 6 | 7 | /// 8 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 9 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 10 | /// any release. You should only use it directly in your code with extreme caution and knowing that 11 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 12 | /// 13 | public sealed class JsonBitArrayReaderWriter : JsonValueReaderWriter 14 | { 15 | /// 16 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 17 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 18 | /// any release. You should only use it directly in your code with extreme caution and knowing that 19 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 20 | /// 21 | public static JsonBitArrayReaderWriter Instance { get; } = new(); 22 | 23 | /// 24 | public override BitArray FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null) 25 | { 26 | var s = manager.CurrentReader.GetString()!; 27 | 28 | var bitArray = new BitArray(s.Length); 29 | 30 | for (var i = 0; i < s.Length; i++) 31 | { 32 | bitArray[i] = s[i] switch 33 | { 34 | '1' => true, 35 | '0' => false, 36 | _ => throw new InvalidOperationException($"Invalid character '{s[i]}' in BitArray string representation in JSON") 37 | }; 38 | } 39 | 40 | return bitArray; 41 | } 42 | 43 | /// 44 | public override void ToJsonTyped(Utf8JsonWriter writer, BitArray value) 45 | => writer.WriteStringValue( 46 | string.Create( 47 | value.Length, value, (s, a) => 48 | { 49 | for (var i = 0; i < s.Length; i++) 50 | { 51 | s[i] = a[i] ? '1' : '0'; 52 | } 53 | })); 54 | } 55 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBEStringTypeMapping.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | /// 4 | /// Represents a so-called PostgreSQL E-string literal string, which allows C-style escape sequences. 5 | /// This is a "virtual" type mapping which is never returned by . 6 | /// It is only used internally by some method translators to produce literal strings. 7 | /// 8 | /// 9 | /// See https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS 10 | /// 11 | public class GaussDBEStringTypeMapping : StringTypeMapping 12 | { 13 | /// 14 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 15 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 16 | /// any release. You should only use it directly in your code with extreme caution and knowing that 17 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 18 | /// 19 | public new static GaussDBEStringTypeMapping Default { get; } = new(); 20 | 21 | /// 22 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 23 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 24 | /// any release. You should only use it directly in your code with extreme caution and knowing that 25 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 26 | /// 27 | public GaussDBEStringTypeMapping() 28 | : base("does_not_exist", System.Data.DbType.String) 29 | { 30 | } 31 | 32 | /// 33 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 34 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 35 | /// any release. You should only use it directly in your code with extreme caution and knowing that 36 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 37 | /// 38 | protected override string GenerateNonNullSqlLiteral(object value) 39 | => $"E'{EscapeSqlLiteral((string)value)}'"; 40 | } 41 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQueryTranslationPreprocessor.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public class GaussDBQueryTranslationPreprocessor : RelationalQueryTranslationPreprocessor 12 | { 13 | private readonly IGaussDBSingletonOptions _GaussDBSingletonOptions; 14 | 15 | /// 16 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 17 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 18 | /// any release. You should only use it directly in your code with extreme caution and knowing that 19 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 20 | /// 21 | public GaussDBQueryTranslationPreprocessor( 22 | QueryTranslationPreprocessorDependencies dependencies, 23 | RelationalQueryTranslationPreprocessorDependencies relationalDependencies, 24 | IGaussDBSingletonOptions GaussDBSingletonOptions, 25 | QueryCompilationContext queryCompilationContext) 26 | : base(dependencies, relationalDependencies, queryCompilationContext) 27 | { 28 | _GaussDBSingletonOptions = GaussDBSingletonOptions; 29 | } 30 | 31 | /// 32 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 33 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 34 | /// any release. You should only use it directly in your code with extreme caution and knowing that 35 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 36 | /// 37 | protected override Expression ProcessQueryRoots(Expression expression) 38 | => new GaussDBQueryRootProcessor(Dependencies, RelationalDependencies, QueryCompilationContext, _GaussDBSingletonOptions) 39 | .Visit(expression); 40 | } 41 | -------------------------------------------------------------------------------- /EFCore.GaussDB.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34322.80 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4A5A60DD-41B6-40BF-B677-227A921ECCC8}" 7 | ProjectSection(SolutionItems) = preProject 8 | Directory.Build.props = Directory.Build.props 9 | Directory.Packages.props = Directory.Packages.props 10 | global.json = global.json 11 | Npgsql.snk = Npgsql.snk 12 | NuGet.config = NuGet.config 13 | README.md = README.md 14 | EndProjectSection 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8537E50E-CF7F-49CB-B4EF-3E2A1B11F050}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{ED612DB1-AB32-4603-95E7-891BACA71C39}" 19 | EndProject 20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.GaussDB", "src\EFCore.GaussDB\EFCore.GaussDB.csproj", "{FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}" 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | Debug|x64 = Debug|x64 26 | Debug|x86 = Debug|x86 27 | Release|Any CPU = Release|Any CPU 28 | Release|x64 = Release|x64 29 | Release|x86 = Release|x86 30 | EndGlobalSection 31 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 32 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Debug|x86.ActiveCfg = Debug|Any CPU 36 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Release|x64.ActiveCfg = Release|Any CPU 39 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Release|x86.ActiveCfg = Release|Any CPU 40 | EndGlobalSection 41 | GlobalSection(SolutionProperties) = preSolution 42 | HideSolutionNode = FALSE 43 | EndGlobalSection 44 | GlobalSection(NestedProjects) = preSolution 45 | {FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A} = {8537E50E-CF7F-49CB-B4EF-3E2A1B11F050} 46 | EndGlobalSection 47 | GlobalSection(ExtensibilityGlobals) = postSolution 48 | SolutionGuid = {F4EAAE6D-758C-4184-9D8C-7113384B61A8} 49 | EndGlobalSection 50 | GlobalSection(MonoDevelopProperties) = preSolution 51 | StartupItem = Npgsql.csproj 52 | EndGlobalSection 53 | EndGlobal 54 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQueryRootProcessor.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public class GaussDBQueryRootProcessor : RelationalQueryRootProcessor 12 | { 13 | private readonly bool _supportsUnnest; 14 | 15 | /// 16 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 17 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 18 | /// any release. You should only use it directly in your code with extreme caution and knowing that 19 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 20 | /// 21 | public GaussDBQueryRootProcessor( 22 | QueryTranslationPreprocessorDependencies dependencies, 23 | RelationalQueryTranslationPreprocessorDependencies relationalDependencies, 24 | QueryCompilationContext queryCompilationContext, 25 | IGaussDBSingletonOptions GaussDBSingletonOptions) 26 | : base(dependencies, relationalDependencies, queryCompilationContext) 27 | { 28 | _supportsUnnest = !GaussDBSingletonOptions.UseRedshift; 29 | } 30 | 31 | /// 32 | /// Converts a to a , to be later translated to 33 | /// PostgreSQL unnest over an array parameter. 34 | /// 35 | /// 36 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 37 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 38 | /// any release. You should only use it directly in your code with extreme caution and knowing that 39 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 40 | /// 41 | protected override bool ShouldConvertToParameterQueryRoot(ParameterExpression parameterExpression) 42 | => _supportsUnnest; 43 | } 44 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBNewGuidTranslator.cs: -------------------------------------------------------------------------------- 1 | using static GaussDB.EntityFrameworkCore.PostgreSQL.Utilities.Statics; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 4 | 5 | /// 6 | /// Provides translation services for PostgreSQL UUID functions. 7 | /// 8 | /// 9 | /// See: https://www.postgresql.org/docs/current/datatype-uuid.html 10 | /// 11 | public class GaussDBNewGuidTranslator : IMethodCallTranslator 12 | { 13 | private static readonly MethodInfo MethodInfo = typeof(Guid).GetRuntimeMethod(nameof(Guid.NewGuid), Array.Empty())!; 14 | 15 | private readonly ISqlExpressionFactory _sqlExpressionFactory; 16 | private readonly string _uuidGenerationFunction; 17 | 18 | /// 19 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 20 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 21 | /// any release. You should only use it directly in your code with extreme caution and knowing that 22 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 23 | /// 24 | public GaussDBNewGuidTranslator(ISqlExpressionFactory sqlExpressionFactory, Version? postgresVersion) 25 | { 26 | _sqlExpressionFactory = sqlExpressionFactory; 27 | _uuidGenerationFunction = postgresVersion.AtLeast(13) ? "gen_random_uuid" : "uuid_generate_v4"; 28 | } 29 | 30 | /// 31 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 32 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 33 | /// any release. You should only use it directly in your code with extreme caution and knowing that 34 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 35 | /// 36 | public virtual SqlExpression? Translate( 37 | SqlExpression? instance, 38 | MethodInfo method, 39 | IReadOnlyList arguments, 40 | IDiagnosticsLogger logger) 41 | => MethodInfo.Equals(method) 42 | ? _sqlExpressionFactory.Function( 43 | _uuidGenerationFunction, 44 | Array.Empty(), 45 | nullable: false, 46 | argumentsPropagateNullability: FalseArrays[0], 47 | method.ReturnType) 48 | : null; 49 | } 50 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBUIntTypeMapping.cs: -------------------------------------------------------------------------------- 1 | using GaussDBTypes; 2 | using Microsoft.EntityFrameworkCore.Storage.Json; 3 | 4 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 5 | 6 | /// 7 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 8 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 9 | /// any release. You should only use it directly in your code with extreme caution and knowing that 10 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 11 | /// 12 | public class GaussDBUIntTypeMapping : GaussDBTypeMapping 13 | { 14 | /// 15 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 16 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 17 | /// any release. You should only use it directly in your code with extreme caution and knowing that 18 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 19 | /// 20 | public GaussDBUIntTypeMapping(string storeType, GaussDBDbType GaussDBDbType) 21 | : base(storeType, typeof(uint), GaussDBDbType, JsonUInt32ReaderWriter.Instance) 22 | { 23 | } 24 | 25 | /// 26 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 27 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 28 | /// any release. You should only use it directly in your code with extreme caution and knowing that 29 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 30 | /// 31 | protected GaussDBUIntTypeMapping(RelationalTypeMappingParameters parameters, GaussDBDbType GaussDBDbType) 32 | : base(parameters, GaussDBDbType) 33 | { 34 | } 35 | 36 | /// 37 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 38 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 39 | /// any release. You should only use it directly in your code with extreme caution and knowing that 40 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 41 | /// 42 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 43 | => new GaussDBUIntTypeMapping(parameters, GaussDBDbType); 44 | } 45 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Update/Internal/GaussDBModificationCommandBatchFactory.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Update.Internal; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public class GaussDBModificationCommandBatchFactory : IModificationCommandBatchFactory 12 | { 13 | private const int DefaultMaxBatchSize = 1000; 14 | 15 | private readonly ModificationCommandBatchFactoryDependencies _dependencies; 16 | private readonly int _maxBatchSize; 17 | 18 | /// 19 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 20 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 21 | /// any release. You should only use it directly in your code with extreme caution and knowing that 22 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 23 | /// 24 | public GaussDBModificationCommandBatchFactory(ModificationCommandBatchFactoryDependencies dependencies, IDbContextOptions options) 25 | { 26 | Check.NotNull(dependencies, nameof(dependencies)); 27 | Check.NotNull(options, nameof(options)); 28 | 29 | _dependencies = dependencies; 30 | 31 | _maxBatchSize = options.FindExtension()?.MaxBatchSize ?? DefaultMaxBatchSize; 32 | 33 | if (_maxBatchSize <= 0) 34 | { 35 | throw new ArgumentOutOfRangeException( 36 | nameof(RelationalOptionsExtension.MaxBatchSize), RelationalStrings.InvalidMaxBatchSize(_maxBatchSize)); 37 | } 38 | } 39 | 40 | /// 41 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 42 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 43 | /// any release. You should only use it directly in your code with extreme caution and knowing that 44 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 45 | /// 46 | public virtual ModificationCommandBatch Create() 47 | => new GaussDBModificationCommandBatch(_dependencies, _maxBatchSize); 48 | } 49 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/GaussDBDatabaseModelExtensions.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace Microsoft.EntityFrameworkCore; 5 | 6 | /// 7 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 8 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 9 | /// any release. You should only use it directly in your code with extreme caution and knowing that 10 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 11 | /// 12 | public static class GaussDBDatabaseModelExtensions 13 | { 14 | /// 15 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 16 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 17 | /// any release. You should only use it directly in your code with extreme caution and knowing that 18 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 19 | /// 20 | public static PostgresExtension GetOrAddPostgresExtension( 21 | this DatabaseModel model, 22 | string? schema, 23 | string name, 24 | string? version) 25 | => PostgresExtension.GetOrAddPostgresExtension(model, schema, name, version); 26 | 27 | /// 28 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 29 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 30 | /// any release. You should only use it directly in your code with extreme caution and knowing that 31 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 32 | /// 33 | public static IReadOnlyList GetPostgresExtensions(this DatabaseModel model) 34 | => PostgresExtension.GetPostgresExtensions(model).ToArray(); 35 | 36 | /// 37 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 38 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 39 | /// any release. You should only use it directly in your code with extreme caution and knowing that 40 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 41 | /// 42 | public static IReadOnlyList GetPostgresEnums(this DatabaseModel model) 43 | => PostgresEnum.GetPostgresEnums(model).ToArray(); 44 | } 45 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBRandomTranslator.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBRandomTranslator : IMethodCallTranslator 10 | { 11 | private static readonly MethodInfo _methodInfo 12 | = typeof(DbFunctionsExtensions).GetRuntimeMethod(nameof(DbFunctionsExtensions.Random), new[] { typeof(DbFunctions) })!; 13 | 14 | private readonly ISqlExpressionFactory _sqlExpressionFactory; 15 | 16 | /// 17 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 18 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 19 | /// any release. You should only use it directly in your code with extreme caution and knowing that 20 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 21 | /// 22 | public GaussDBRandomTranslator(ISqlExpressionFactory sqlExpressionFactory) 23 | { 24 | _sqlExpressionFactory = sqlExpressionFactory; 25 | } 26 | 27 | /// 28 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 29 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 30 | /// any release. You should only use it directly in your code with extreme caution and knowing that 31 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 32 | /// 33 | public virtual SqlExpression? Translate( 34 | SqlExpression? instance, 35 | MethodInfo method, 36 | IReadOnlyList arguments, 37 | IDiagnosticsLogger logger) 38 | { 39 | Check.NotNull(method, nameof(method)); 40 | Check.NotNull(arguments, nameof(arguments)); 41 | Check.NotNull(logger, nameof(logger)); 42 | 43 | return _methodInfo.Equals(method) 44 | ? _sqlExpressionFactory.Function( 45 | "random", 46 | Array.Empty(), 47 | nullable: false, 48 | argumentsPropagateNullability: Array.Empty(), 49 | method.ReturnType) 50 | : null; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBBigIntegerMemberTranslator.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public class GaussDBBigIntegerMemberTranslator : IMemberTranslator 12 | { 13 | private readonly GaussDBSqlExpressionFactory _sqlExpressionFactory; 14 | 15 | private static readonly MemberInfo IsZero = typeof(BigInteger).GetProperty(nameof(BigInteger.IsZero))!; 16 | private static readonly MemberInfo IsOne = typeof(BigInteger).GetProperty(nameof(BigInteger.IsOne))!; 17 | private static readonly MemberInfo IsEven = typeof(BigInteger).GetProperty(nameof(BigInteger.IsEven))!; 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public GaussDBBigIntegerMemberTranslator(GaussDBSqlExpressionFactory sqlExpressionFactory) 26 | { 27 | _sqlExpressionFactory = sqlExpressionFactory; 28 | } 29 | 30 | /// 31 | public virtual SqlExpression? Translate( 32 | SqlExpression? instance, 33 | MemberInfo member, 34 | Type returnType, 35 | IDiagnosticsLogger logger) 36 | { 37 | if (member.DeclaringType == typeof(BigInteger)) 38 | { 39 | if (member == IsZero) 40 | { 41 | return _sqlExpressionFactory.Equal(instance!, _sqlExpressionFactory.Constant(BigInteger.Zero)); 42 | } 43 | 44 | if (member == IsOne) 45 | { 46 | return _sqlExpressionFactory.Equal(instance!, _sqlExpressionFactory.Constant(BigInteger.One)); 47 | } 48 | 49 | if (member == IsEven) 50 | { 51 | return _sqlExpressionFactory.Equal( 52 | _sqlExpressionFactory.Modulo(instance!, _sqlExpressionFactory.Constant(new BigInteger(2))), 53 | _sqlExpressionFactory.Constant(BigInteger.Zero)); 54 | } 55 | } 56 | 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBParameterBasedSqlProcessor.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBParameterBasedSqlProcessor : RelationalParameterBasedSqlProcessor 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public GaussDBParameterBasedSqlProcessor( 18 | RelationalParameterBasedSqlProcessorDependencies dependencies, 19 | bool useRelationalNulls) 20 | : base(dependencies, useRelationalNulls) 21 | { 22 | } 23 | 24 | /// 25 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 26 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 27 | /// any release. You should only use it directly in your code with extreme caution and knowing that 28 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 29 | /// 30 | public override Expression Optimize( 31 | Expression queryExpression, 32 | IReadOnlyDictionary parametersValues, 33 | out bool canCache) 34 | { 35 | queryExpression = base.Optimize(queryExpression, parametersValues, out canCache); 36 | 37 | queryExpression = new GaussDBDeleteConvertingExpressionVisitor().Process(queryExpression); 38 | 39 | return queryExpression; 40 | } 41 | 42 | /// 43 | protected override Expression ProcessSqlNullability( 44 | Expression selectExpression, 45 | IReadOnlyDictionary parametersValues, 46 | out bool canCache) 47 | { 48 | Check.NotNull(selectExpression, nameof(selectExpression)); 49 | Check.NotNull(parametersValues, nameof(parametersValues)); 50 | 51 | return new GaussDBSqlNullabilityProcessor(Dependencies, UseRelationalNulls).Process( 52 | selectExpression, parametersValues, out canCache); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/GaussDBDatabaseFacadeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 3 | using GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Microsoft.EntityFrameworkCore; 7 | 8 | /// 9 | /// GaussDB specific extension methods for . 10 | /// 11 | public static class GaussDBDatabaseFacadeExtensions 12 | { 13 | /// 14 | /// 15 | /// Returns true if the database provider currently in use is the GaussDB provider. 16 | /// 17 | /// 18 | /// This method can only be used after the has been configured because 19 | /// it is only then that the provider is known. This means that this method cannot be used 20 | /// in because this is where application code sets the 21 | /// provider to use as part of configuring the context. 22 | /// 23 | /// 24 | /// The facade from . 25 | /// True if GaussDB is being used; false otherwise. 26 | public static bool IsGaussDB(this DatabaseFacade database) 27 | => database.ProviderName == typeof(GaussDBOptionsExtension).GetTypeInfo().Assembly.GetName().Name; 28 | 29 | /// 30 | /// Sets the underlying configured for this . 31 | /// 32 | /// 33 | /// 34 | /// It may not be possible to change the data source if existing connection, if any, is open. 35 | /// 36 | /// 37 | /// See Connections and connection strings for more information and examples. 38 | /// 39 | /// 40 | /// The for the context. 41 | /// The connection string. 42 | public static void SetDbDataSource(this DatabaseFacade databaseFacade, DbDataSource dataSource) 43 | => ((GaussDBRelationalConnection)GetFacadeDependencies(databaseFacade).RelationalConnection).DbDataSource = dataSource; 44 | 45 | private static IRelationalDatabaseFacadeDependencies GetFacadeDependencies(DatabaseFacade databaseFacade) 46 | { 47 | var dependencies = ((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies; 48 | 49 | if (dependencies is IRelationalDatabaseFacadeDependencies relationalDependencies) 50 | { 51 | return relationalDependencies; 52 | } 53 | 54 | throw new InvalidOperationException(RelationalStrings.RelationalNotInUse); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQueryTranslationPreprocessorFactory.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public class GaussDBQueryTranslationPreprocessorFactory : IQueryTranslationPreprocessorFactory 12 | { 13 | private readonly IGaussDBSingletonOptions _GaussDBSingletonOptions; 14 | 15 | /// 16 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 17 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 18 | /// any release. You should only use it directly in your code with extreme caution and knowing that 19 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 20 | /// 21 | public GaussDBQueryTranslationPreprocessorFactory( 22 | QueryTranslationPreprocessorDependencies dependencies, 23 | RelationalQueryTranslationPreprocessorDependencies relationalDependencies, 24 | IGaussDBSingletonOptions GaussDBSingletonOptions) 25 | { 26 | Dependencies = dependencies; 27 | RelationalDependencies = relationalDependencies; 28 | _GaussDBSingletonOptions = GaussDBSingletonOptions; 29 | } 30 | 31 | /// 32 | /// Dependencies for this service. 33 | /// 34 | protected virtual QueryTranslationPreprocessorDependencies Dependencies { get; } 35 | 36 | /// 37 | /// Relational provider-specific dependencies for this service. 38 | /// 39 | protected virtual RelationalQueryTranslationPreprocessorDependencies RelationalDependencies { get; } 40 | 41 | /// 42 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 43 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 44 | /// any release. You should only use it directly in your code with extreme caution and knowing that 45 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 46 | /// 47 | public virtual QueryTranslationPreprocessor Create(QueryCompilationContext queryCompilationContext) 48 | => new GaussDBQueryTranslationPreprocessor(Dependencies, RelationalDependencies, _GaussDBSingletonOptions, queryCompilationContext); 49 | } 50 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8.0.2 4 | preview 5 | true 6 | latest 7 | NU5105 8 | true 9 | $(MSBuildThisFileDirectory)Npgsql.snk 10 | true 11 | true 12 | true 13 | true 14 | 修复GaussDB 3.1.0版本中使用EF.Functions.Like方法翻译无法命中BUG 15 | true 16 | PostgreSQL 17 | https://github.com/dotnetcore/EntityFrameworkCore.GaussDB 18 | icon.png 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBMemberTranslatorProvider.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 4 | 5 | /// 6 | /// A composite member translator that dispatches to multiple specialized member translators specific to GaussDB. 7 | /// 8 | public class GaussDBMemberTranslatorProvider : RelationalMemberTranslatorProvider 9 | { 10 | /// 11 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 12 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 13 | /// any release. You should only use it directly in your code with extreme caution and knowing that 14 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 15 | /// 16 | public virtual GaussDBJsonPocoTranslator JsonPocoTranslator { get; } 17 | 18 | /// 19 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 20 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 21 | /// any release. You should only use it directly in your code with extreme caution and knowing that 22 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 23 | /// 24 | public GaussDBMemberTranslatorProvider( 25 | RelationalMemberTranslatorProviderDependencies dependencies, 26 | IModel model, 27 | IRelationalTypeMappingSource typeMappingSource, 28 | IDbContextOptions contextOptions) 29 | : base(dependencies) 30 | { 31 | var GaussDBOptions = contextOptions.FindExtension() ?? new GaussDBOptionsExtension(); 32 | var supportsMultiranges = GaussDBOptions.PostgresVersion.AtLeast(14); 33 | 34 | var sqlExpressionFactory = (GaussDBSqlExpressionFactory)dependencies.SqlExpressionFactory; 35 | JsonPocoTranslator = new GaussDBJsonPocoTranslator(typeMappingSource, sqlExpressionFactory, model); 36 | 37 | AddTranslators( 38 | new IMemberTranslator[] 39 | { 40 | new GaussDBBigIntegerMemberTranslator(sqlExpressionFactory), 41 | new GaussDBDateTimeMemberTranslator(typeMappingSource, sqlExpressionFactory), 42 | new GaussDBJsonDomTranslator(typeMappingSource, sqlExpressionFactory, model), 43 | new GaussDBLTreeTranslator(typeMappingSource, sqlExpressionFactory, model), 44 | JsonPocoTranslator, 45 | new GaussDBRangeTranslator(typeMappingSource, sqlExpressionFactory, model, supportsMultiranges), 46 | new GaussDBStringMemberTranslator(sqlExpressionFactory), 47 | new GaussDBTimeSpanMemberTranslator(sqlExpressionFactory), 48 | }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /.build/server.crt: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 3 (0x2) 4 | Serial Number: 12599801177921850358 (0xaedb7c6a2a948bf6) 5 | Signature Algorithm: sha1WithRSAEncryption 6 | Issuer: C=AU, ST=Some-State, O=Internet Widgits Pty Ltd, CN=localhost 7 | Validity 8 | Not Before: Mar 13 11:19:37 2015 GMT 9 | Not After : Apr 12 11:19:37 2015 GMT 10 | Subject: C=AU, ST=Some-State, O=Internet Widgits Pty Ltd, CN=localhost 11 | Subject Public Key Info: 12 | Public Key Algorithm: rsaEncryption 13 | Public-Key: (1024 bit) 14 | Modulus: 15 | 00:c1:df:3f:3b:b8:59:b1:33:ae:9c:ec:6b:44:41: 16 | 7b:0a:cd:51:62:98:e2:11:f0:a0:7d:65:67:9b:49: 17 | 88:15:91:cf:30:f1:23:dc:3c:00:83:76:be:59:df: 18 | 9c:66:8f:eb:f3:a7:73:a0:eb:2a:26:85:d2:48:aa: 19 | 4f:88:1b:b8:31:22:df:bd:e3:1b:6f:4f:70:c3:b2: 20 | f4:a8:14:07:0e:77:d7:fe:91:b1:b1:3d:0a:cc:5e: 21 | 32:ac:31:06:d3:d7:cf:e5:fc:3c:c0:db:c0:6b:0e: 22 | 00:e0:a5:32:4a:2d:90:63:37:7e:c8:e6:5d:ad:df: 23 | 30:81:7e:65:4a:6d:71:a5:9b 24 | Exponent: 65537 (0x10001) 25 | X509v3 extensions: 26 | X509v3 Subject Key Identifier: 27 | 17:4C:64:08:33:71:2A:34:33:CA:15:3E:F3:B8:98:1A:E7:8E:64:F4 28 | X509v3 Authority Key Identifier: 29 | keyid:17:4C:64:08:33:71:2A:34:33:CA:15:3E:F3:B8:98:1A:E7:8E:64:F4 30 | 31 | X509v3 Basic Constraints: 32 | CA:TRUE 33 | Signature Algorithm: sha1WithRSAEncryption 34 | 81:f4:69:3e:b1:c0:9f:4b:82:10:8d:3e:7c:98:70:2a:f3:24: 35 | ca:33:13:35:1d:9e:84:dc:b4:f1:17:1f:e6:18:d5:86:51:b3: 36 | ce:3e:4a:97:39:cc:7e:74:94:01:da:68:43:df:b0:b6:fc:29: 37 | 0c:86:ce:5f:0c:3d:c6:f0:8c:c0:f5:86:e7:0b:3f:fb:b0:d6: 38 | b0:2c:9a:9e:15:be:31:dc:6d:bb:32:92:b7:36:fb:65:5a:f1: 39 | d2:44:04:fe:eb:97:f2:8a:31:2e:4c:fd:f9:80:00:8d:91:81: 40 | c1:90:97:18:fa:e2:c6:1c:ff:28:d1:58:94:b3:b5:9f:7a:f7: 41 | 39:b3 42 | -----BEGIN CERTIFICATE----- 43 | MIICgDCCAemgAwIBAgIJAK7bfGoqlIv2MA0GCSqGSIb3DQEBBQUAMFkxCzAJBgNV 44 | BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX 45 | aWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0xNTAzMTMxMTE5 46 | MzdaFw0xNTA0MTIxMTE5MzdaMFkxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21l 47 | LVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNV 48 | BAMMCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwd8/O7hZ 49 | sTOunOxrREF7Cs1RYpjiEfCgfWVnm0mIFZHPMPEj3DwAg3a+Wd+cZo/r86dzoOsq 50 | JoXSSKpPiBu4MSLfveMbb09ww7L0qBQHDnfX/pGxsT0KzF4yrDEG09fP5fw8wNvA 51 | aw4A4KUySi2QYzd+yOZdrd8wgX5lSm1xpZsCAwEAAaNQME4wHQYDVR0OBBYEFBdM 52 | ZAgzcSo0M8oVPvO4mBrnjmT0MB8GA1UdIwQYMBaAFBdMZAgzcSo0M8oVPvO4mBrn 53 | jmT0MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAgfRpPrHAn0uCEI0+ 54 | fJhwKvMkyjMTNR2ehNy08Rcf5hjVhlGzzj5KlznMfnSUAdpoQ9+wtvwpDIbOXww9 55 | xvCMwPWG5ws/+7DWsCyanhW+MdxtuzKStzb7ZVrx0kQE/uuX8ooxLkz9+YAAjZGB 56 | wZCXGPrixhz/KNFYlLO1n3r3ObM= 57 | -----END CERTIFICATE----- 58 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBRegexIsMatchTranslator.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | using ExpressionExtensions = Microsoft.EntityFrameworkCore.Query.ExpressionExtensions; 3 | 4 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 5 | 6 | /// 7 | /// Translates Regex.IsMatch calls into PostgreSQL regex expressions for database-side processing. 8 | /// 9 | /// 10 | /// http://www.postgresql.org/docs/current/static/functions-matching.html 11 | /// 12 | public class GaussDBRegexIsMatchTranslator : IMethodCallTranslator 13 | { 14 | private static readonly MethodInfo IsMatch = 15 | typeof(Regex).GetRuntimeMethod(nameof(Regex.IsMatch), new[] { typeof(string), typeof(string) })!; 16 | 17 | private static readonly MethodInfo IsMatchWithRegexOptions = 18 | typeof(Regex).GetRuntimeMethod(nameof(Regex.IsMatch), new[] { typeof(string), typeof(string), typeof(RegexOptions) })!; 19 | 20 | private const RegexOptions UnsupportedRegexOptions = RegexOptions.RightToLeft | RegexOptions.ECMAScript; 21 | 22 | private readonly GaussDBSqlExpressionFactory _sqlExpressionFactory; 23 | 24 | /// 25 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 26 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 27 | /// any release. You should only use it directly in your code with extreme caution and knowing that 28 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 29 | /// 30 | public GaussDBRegexIsMatchTranslator(GaussDBSqlExpressionFactory sqlExpressionFactory) 31 | { 32 | _sqlExpressionFactory = sqlExpressionFactory; 33 | } 34 | 35 | /// 36 | public virtual SqlExpression? Translate( 37 | SqlExpression? instance, 38 | MethodInfo method, 39 | IReadOnlyList arguments, 40 | IDiagnosticsLogger logger) 41 | { 42 | if (method != IsMatch && method != IsMatchWithRegexOptions) 43 | { 44 | return null; 45 | } 46 | 47 | var (input, pattern) = (arguments[0], arguments[1]); 48 | var typeMapping = ExpressionExtensions.InferTypeMapping(input, pattern); 49 | 50 | RegexOptions options; 51 | 52 | if (method == IsMatch) 53 | { 54 | options = RegexOptions.None; 55 | } 56 | else if (arguments[2] is SqlConstantExpression { Value: RegexOptions regexOptions }) 57 | { 58 | options = regexOptions; 59 | } 60 | else 61 | { 62 | return null; // We don't support non-constant regex options 63 | } 64 | 65 | return (options & UnsupportedRegexOptions) == 0 66 | ? _sqlExpressionFactory.RegexMatch( 67 | _sqlExpressionFactory.ApplyTypeMapping(input, typeMapping), 68 | _sqlExpressionFactory.ApplyTypeMapping(pattern, typeMapping), 69 | options) 70 | : null; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Metadata/GaussDBValueGenerationStrategy.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; 2 | 3 | /// 4 | /// Defines strategies to use when generating values for database columns. 5 | /// 6 | /// 7 | /// See Model building conventions. 8 | /// 9 | public enum GaussDBValueGenerationStrategy 10 | { 11 | /// 12 | /// No GaussDB-specific strategy. 13 | /// 14 | None, 15 | 16 | /// 17 | /// 18 | /// A sequence-based hi-lo pattern where blocks of IDs are allocated from the server and 19 | /// used client-side for generating keys. 20 | /// 21 | /// 22 | /// This is an advanced pattern--only use this strategy if you are certain it is what you need. 23 | /// 24 | /// 25 | SequenceHiLo, 26 | 27 | /// 28 | /// 29 | /// Selects the serial column strategy, which is a regular column backed by an auto-created index. 30 | /// 31 | /// 32 | /// If you are creating a new project on PostgreSQL 10 or above, consider using instead. 33 | /// 34 | /// 35 | SerialColumn, 36 | 37 | /// 38 | /// Selects the always-identity column strategy (a value cannot be provided). 39 | /// Available only starting PostgreSQL 10. 40 | /// 41 | IdentityAlwaysColumn, 42 | 43 | /// 44 | /// Selects the by-default-identity column strategy (a value can be provided to override the identity mechanism). 45 | /// Available only starting PostgreSQL 10. 46 | /// 47 | IdentityByDefaultColumn, 48 | 49 | /// 50 | /// A pattern that uses a database sequence to generate values for the column. 51 | /// 52 | Sequence 53 | } 54 | 55 | /// 56 | /// Extension methods over . 57 | /// 58 | public static class GaussDBValueGenerationStrategyExtensions 59 | { 60 | /// 61 | /// Whether the given strategy is either or 62 | /// . 63 | /// 64 | public static bool IsIdentity(this GaussDBValueGenerationStrategy strategy) 65 | => strategy is GaussDBValueGenerationStrategy.IdentityByDefaultColumn or GaussDBValueGenerationStrategy.IdentityAlwaysColumn; 66 | 67 | /// 68 | /// Whether the given strategy is either or 69 | /// . 70 | /// 71 | public static bool IsIdentity(this GaussDBValueGenerationStrategy? strategy) 72 | => strategy is GaussDBValueGenerationStrategy.IdentityByDefaultColumn or GaussDBValueGenerationStrategy.IdentityAlwaysColumn; 73 | } 74 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBConvertTranslator.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 2 | 3 | /// 4 | /// Translates methods defined on into PostgreSQL CAST expressions. 5 | /// 6 | public class GaussDBConvertTranslator : IMethodCallTranslator 7 | { 8 | private static readonly Dictionary TypeMapping = new() 9 | { 10 | [nameof(Convert.ToBoolean)] = "bool", 11 | [nameof(Convert.ToByte)] = "smallint", 12 | [nameof(Convert.ToDecimal)] = "numeric", 13 | [nameof(Convert.ToDouble)] = "double precision", 14 | [nameof(Convert.ToInt16)] = "smallint", 15 | [nameof(Convert.ToInt32)] = "int", 16 | [nameof(Convert.ToInt64)] = "bigint", 17 | [nameof(Convert.ToString)] = "text" 18 | }; 19 | 20 | private static readonly List SupportedTypes = new() 21 | { 22 | typeof(bool), 23 | typeof(byte), 24 | typeof(decimal), 25 | typeof(double), 26 | typeof(float), 27 | typeof(int), 28 | typeof(long), 29 | typeof(short), 30 | typeof(string) 31 | }; 32 | 33 | private static readonly List SupportedMethods 34 | = TypeMapping.Keys 35 | .SelectMany( 36 | t => typeof(Convert).GetTypeInfo().GetDeclaredMethods(t) 37 | .Where( 38 | m => m.GetParameters().Length == 1 39 | && SupportedTypes.Contains(m.GetParameters().First().ParameterType))) 40 | .ToList(); 41 | 42 | private readonly ISqlExpressionFactory _sqlExpressionFactory; 43 | 44 | /// 45 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 46 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 47 | /// any release. You should only use it directly in your code with extreme caution and knowing that 48 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 49 | /// 50 | public GaussDBConvertTranslator(ISqlExpressionFactory sqlExpressionFactory) 51 | { 52 | _sqlExpressionFactory = sqlExpressionFactory; 53 | } 54 | 55 | /// 56 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 57 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 58 | /// any release. You should only use it directly in your code with extreme caution and knowing that 59 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 60 | /// 61 | public virtual SqlExpression? Translate( 62 | SqlExpression? instance, 63 | MethodInfo method, 64 | IReadOnlyList arguments, 65 | IDiagnosticsLogger logger) 66 | => SupportedMethods.Contains(method) 67 | ? _sqlExpressionFactory.Convert(arguments[0], method.ReturnType) 68 | : null; 69 | } 70 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBULongTypeMapping.cs: -------------------------------------------------------------------------------- 1 | using GaussDBTypes; 2 | using Microsoft.EntityFrameworkCore.Storage.Json; 3 | 4 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 5 | 6 | /// 7 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 8 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 9 | /// any release. You should only use it directly in your code with extreme caution and knowing that 10 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 11 | /// 12 | public class GaussDBULongTypeMapping : GaussDBTypeMapping 13 | { 14 | /// 15 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 16 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 17 | /// any release. You should only use it directly in your code with extreme caution and knowing that 18 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 19 | /// 20 | public static GaussDBULongTypeMapping Default { get; } = new("xid8", GaussDBDbType.Xid8); 21 | 22 | /// 23 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 24 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 25 | /// any release. You should only use it directly in your code with extreme caution and knowing that 26 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 27 | /// 28 | public GaussDBULongTypeMapping(string storeType, GaussDBDbType GaussDBDbType) 29 | : base(storeType, typeof(ulong), GaussDBDbType, JsonUInt64ReaderWriter.Instance) 30 | { 31 | } 32 | 33 | /// 34 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 35 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 36 | /// any release. You should only use it directly in your code with extreme caution and knowing that 37 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 38 | /// 39 | protected GaussDBULongTypeMapping(RelationalTypeMappingParameters parameters, GaussDBDbType gaussDBDbType) 40 | : base(parameters, gaussDBDbType) 41 | { 42 | } 43 | 44 | /// 45 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 46 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 47 | /// any release. You should only use it directly in your code with extreme caution and knowing that 48 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 49 | /// 50 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 51 | => new GaussDBULongTypeMapping(parameters, GaussDBDbType); 52 | } 53 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Metadata/Conventions/GaussDBPostgresModelFinalizingConvention.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Metadata.Conventions; 2 | 3 | /// 4 | /// A convention that discovers certain common PostgreSQL extensions based on store types used in the model (e.g. hstore). 5 | /// 6 | /// 7 | /// See Model building conventions. 8 | /// 9 | public class GaussDBPostgresModelFinalizingConvention : IModelFinalizingConvention 10 | { 11 | private readonly IRelationalTypeMappingSource _typeMappingSource; 12 | 13 | /// 14 | /// Creates a new instance of . 15 | /// 16 | /// The type mapping source to use. 17 | public GaussDBPostgresModelFinalizingConvention(IRelationalTypeMappingSource typeMappingSource) 18 | { 19 | _typeMappingSource = typeMappingSource; 20 | } 21 | 22 | /// 23 | public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext context) 24 | { 25 | foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) 26 | { 27 | foreach (var property in entityType.GetDeclaredProperties()) 28 | { 29 | var typeMapping = (RelationalTypeMapping?)property.FindTypeMapping() 30 | ?? _typeMappingSource.FindMapping((IProperty)property); 31 | 32 | if (typeMapping is not null) 33 | { 34 | DiscoverPostgresExtensions(property, typeMapping, modelBuilder); 35 | ProcessRowVersionProperty(property, typeMapping); 36 | } 37 | } 38 | } 39 | } 40 | 41 | /// 42 | /// Discovers certain common PostgreSQL extensions based on property store types (e.g. hstore). 43 | /// 44 | protected virtual void DiscoverPostgresExtensions( 45 | IConventionProperty property, 46 | RelationalTypeMapping typeMapping, 47 | IConventionModelBuilder modelBuilder) 48 | { 49 | switch (typeMapping.StoreType) 50 | { 51 | case "hstore": 52 | modelBuilder.HasPostgresExtension("hstore"); 53 | break; 54 | case "citext": 55 | modelBuilder.HasPostgresExtension("citext"); 56 | break; 57 | case "ltree": 58 | case "lquery": 59 | case "ltxtquery": 60 | modelBuilder.HasPostgresExtension("ltree"); 61 | break; 62 | } 63 | } 64 | 65 | /// 66 | /// Detects properties which are uint, OnAddOrUpdate and configured as concurrency tokens, and maps these to the PostgreSQL 67 | /// internal "xmin" column, which changes every time the row is modified. 68 | /// 69 | protected virtual void ProcessRowVersionProperty(IConventionProperty property, RelationalTypeMapping typeMapping) 70 | { 71 | if (property is { ValueGenerated: ValueGenerated.OnAddOrUpdate, IsConcurrencyToken: true } 72 | && typeMapping.StoreType == "xid") 73 | { 74 | property.Builder.HasColumnName("xmin"); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Expressions/Internal/PgRegexMatchExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; 4 | 5 | /// 6 | /// Represents a PostgreSQL regular expression match expression. 7 | /// 8 | public class PgRegexMatchExpression : SqlExpression, IEquatable 9 | { 10 | /// 11 | public override Type Type 12 | => typeof(bool); 13 | 14 | /// 15 | /// The match expression. 16 | /// 17 | public virtual SqlExpression Match { get; } 18 | 19 | /// 20 | /// The pattern to match. 21 | /// 22 | public virtual SqlExpression Pattern { get; } 23 | 24 | /// 25 | /// The options for regular expression evaluation. 26 | /// 27 | public virtual RegexOptions Options { get; } 28 | 29 | /// 30 | /// Constructs a . 31 | /// 32 | /// The expression to match. 33 | /// The pattern to match. 34 | /// The options for regular expression evaluation. 35 | /// The type mapping for the expression. 36 | public PgRegexMatchExpression( 37 | SqlExpression match, 38 | SqlExpression pattern, 39 | RegexOptions options, 40 | RelationalTypeMapping? typeMapping) 41 | : base(typeof(bool), typeMapping) 42 | { 43 | Match = match; 44 | Pattern = pattern; 45 | Options = options; 46 | } 47 | 48 | /// 49 | protected override Expression VisitChildren(ExpressionVisitor visitor) 50 | => Update((SqlExpression)visitor.Visit(Match), (SqlExpression)visitor.Visit(Pattern)); 51 | 52 | /// 53 | /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will 54 | /// return this expression. 55 | /// 56 | public virtual PgRegexMatchExpression Update(SqlExpression match, SqlExpression pattern) 57 | => match != Match || pattern != Pattern 58 | ? new PgRegexMatchExpression(match, pattern, Options, TypeMapping) 59 | : this; 60 | 61 | /// 62 | public virtual bool Equals(PgRegexMatchExpression? other) 63 | => ReferenceEquals(this, other) 64 | || other is not null 65 | && base.Equals(other) 66 | && Match.Equals(other.Match) 67 | && Pattern.Equals(other.Pattern) 68 | && Options.Equals(other.Options); 69 | 70 | /// 71 | public override bool Equals(object? other) 72 | => other is PgRegexMatchExpression otherRegexMatch && Equals(otherRegexMatch); 73 | 74 | /// 75 | public override int GetHashCode() 76 | => HashCode.Combine(base.GetHashCode(), Match, Pattern, Options); 77 | 78 | /// 79 | protected override void Print(ExpressionPrinter expressionPrinter) 80 | { 81 | expressionPrinter.Visit(Match); 82 | expressionPrinter.Append(" ~ "); 83 | expressionPrinter.Visit(Pattern); 84 | } 85 | 86 | /// 87 | public override string ToString() 88 | => $"{Match} ~ {Pattern}"; 89 | } 90 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBTsRankingNormalizationTypeMapping.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBTsRankingNormalizationTypeMapping : IntTypeMapping 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public static new GaussDBTsRankingNormalizationTypeMapping Default { get; } = new(); 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public GaussDBTsRankingNormalizationTypeMapping() 26 | : base( 27 | new RelationalTypeMappingParameters( 28 | new CoreTypeMappingParameters( 29 | typeof(GaussDBTsRankingNormalization), new EnumToNumberConverter()), 30 | "integer")) 31 | { 32 | } 33 | 34 | /// 35 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 36 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 37 | /// any release. You should only use it directly in your code with extreme caution and knowing that 38 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 39 | /// 40 | protected GaussDBTsRankingNormalizationTypeMapping(RelationalTypeMappingParameters parameters) 41 | : base(parameters) 42 | { 43 | } 44 | 45 | /// 46 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 47 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 48 | /// any release. You should only use it directly in your code with extreme caution and knowing that 49 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 50 | /// 51 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 52 | => new GaussDBTsRankingNormalizationTypeMapping(parameters); 53 | } 54 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBCompiledQueryCacheKeyGenerator.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public class GaussDBCompiledQueryCacheKeyGenerator : RelationalCompiledQueryCacheKeyGenerator 12 | { 13 | /// 14 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 15 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 16 | /// any release. You should only use it directly in your code with extreme caution and knowing that 17 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 18 | /// 19 | public GaussDBCompiledQueryCacheKeyGenerator( 20 | CompiledQueryCacheKeyGeneratorDependencies dependencies, 21 | RelationalCompiledQueryCacheKeyGeneratorDependencies relationalDependencies) 22 | : base(dependencies, relationalDependencies) 23 | { 24 | } 25 | 26 | /// 27 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 28 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 29 | /// any release. You should only use it directly in your code with extreme caution and knowing that 30 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 31 | /// 32 | public override object GenerateCacheKey(Expression query, bool async) 33 | => new GaussDBCompiledQueryCacheKey( 34 | GenerateCacheKeyCore(query, async), 35 | RelationalDependencies.ContextOptions.FindExtension()?.ReverseNullOrdering ?? false); 36 | 37 | private struct GaussDBCompiledQueryCacheKey 38 | { 39 | private readonly RelationalCompiledQueryCacheKey _relationalCompiledQueryCacheKey; 40 | private readonly bool _reverseNullOrdering; 41 | 42 | public GaussDBCompiledQueryCacheKey( 43 | RelationalCompiledQueryCacheKey relationalCompiledQueryCacheKey, 44 | bool reverseNullOrdering) 45 | { 46 | _relationalCompiledQueryCacheKey = relationalCompiledQueryCacheKey; 47 | _reverseNullOrdering = reverseNullOrdering; 48 | } 49 | 50 | public override bool Equals(object? obj) 51 | => !(obj is null) 52 | && obj is GaussDBCompiledQueryCacheKey key 53 | && Equals(key); 54 | 55 | private bool Equals(GaussDBCompiledQueryCacheKey other) 56 | => _relationalCompiledQueryCacheKey.Equals(other._relationalCompiledQueryCacheKey) 57 | && _reverseNullOrdering == other._reverseNullOrdering; 58 | 59 | public override int GetHashCode() 60 | => HashCode.Combine(_relationalCompiledQueryCacheKey, _reverseNullOrdering); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Internal/GaussDBQueryableMethodTranslatingExpressionVisitorFactory.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Internal; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBQueryableMethodTranslatingExpressionVisitorFactory : IQueryableMethodTranslatingExpressionVisitorFactory 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public GaussDBQueryableMethodTranslatingExpressionVisitorFactory( 18 | QueryableMethodTranslatingExpressionVisitorDependencies dependencies, 19 | RelationalQueryableMethodTranslatingExpressionVisitorDependencies relationalDependencies) 20 | { 21 | Dependencies = dependencies; 22 | RelationalDependencies = relationalDependencies; 23 | } 24 | 25 | /// 26 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 27 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 28 | /// any release. You should only use it directly in your code with extreme caution and knowing that 29 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 30 | /// 31 | protected virtual QueryableMethodTranslatingExpressionVisitorDependencies Dependencies { get; } 32 | 33 | /// 34 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 35 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 36 | /// any release. You should only use it directly in your code with extreme caution and knowing that 37 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 38 | /// 39 | protected virtual RelationalQueryableMethodTranslatingExpressionVisitorDependencies RelationalDependencies { get; } 40 | 41 | /// 42 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 43 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 44 | /// any release. You should only use it directly in your code with extreme caution and knowing that 45 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 46 | /// 47 | public virtual QueryableMethodTranslatingExpressionVisitor Create(QueryCompilationContext queryCompilationContext) 48 | => new GaussDBQueryableMethodTranslatingExpressionVisitor(Dependencies, RelationalDependencies, queryCompilationContext); 49 | } 50 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBBoolTypeMapping.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBBoolTypeMapping : BoolTypeMapping 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public static new GaussDBBoolTypeMapping Default { get; } = new(); 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public GaussDBBoolTypeMapping() 26 | : base("boolean") 27 | { 28 | } 29 | 30 | /// 31 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 32 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 33 | /// any release. You should only use it directly in your code with extreme caution and knowing that 34 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 35 | /// 36 | protected GaussDBBoolTypeMapping(RelationalTypeMappingParameters parameters) 37 | : base(parameters) 38 | { 39 | } 40 | 41 | /// 42 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 43 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 44 | /// any release. You should only use it directly in your code with extreme caution and knowing that 45 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 46 | /// 47 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 48 | => new GaussDBBoolTypeMapping(parameters); 49 | 50 | /// 51 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 52 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 53 | /// any release. You should only use it directly in your code with extreme caution and knowing that 54 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 55 | /// 56 | protected override string GenerateNonNullSqlLiteral(object value) 57 | => (bool)value ? "TRUE" : "FALSE"; 58 | } 59 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBMoneyTypeMapping.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBMoneyTypeMapping : DecimalTypeMapping 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public static new GaussDBMoneyTypeMapping Default { get; } = new(); 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public GaussDBMoneyTypeMapping() 26 | : base("money", System.Data.DbType.Currency) 27 | { 28 | } 29 | 30 | /// 31 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 32 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 33 | /// any release. You should only use it directly in your code with extreme caution and knowing that 34 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 35 | /// 36 | protected GaussDBMoneyTypeMapping(RelationalTypeMappingParameters parameters) 37 | : base(parameters) 38 | { 39 | } 40 | 41 | /// 42 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 43 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 44 | /// any release. You should only use it directly in your code with extreme caution and knowing that 45 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 46 | /// 47 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 48 | => new GaussDBMoneyTypeMapping(parameters); 49 | 50 | /// 51 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 52 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 53 | /// any release. You should only use it directly in your code with extreme caution and knowing that 54 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 55 | /// 56 | protected override string GenerateNonNullSqlLiteral(object value) 57 | => base.GenerateNonNullSqlLiteral(value) + "::money"; 58 | } 59 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Expressions/Internal/PgUnknownBinaryExpression.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; 2 | 3 | /// 4 | /// A binary expression only to be used by plugins, since new expressions can only be added (and handled) 5 | /// within the provider itself. Allows defining the operator as a string within the expression, and has 6 | /// default (i.e. propagating) nullability semantics. 7 | /// All type mappings must be applied to the operands before the expression is constructed, since there's 8 | /// no inference logic for it in . 9 | /// 10 | public class PgUnknownBinaryExpression : SqlExpression, IEquatable 11 | { 12 | /// 13 | /// The left-hand expression. 14 | /// 15 | public virtual SqlExpression Left { get; } 16 | 17 | /// 18 | /// The right-hand expression. 19 | /// 20 | public virtual SqlExpression Right { get; } 21 | 22 | /// 23 | /// The operator. 24 | /// 25 | public virtual string Operator { get; } 26 | 27 | /// 28 | /// Constructs a . 29 | /// 30 | /// The left-hand expression. 31 | /// The right-hand expression. 32 | /// The operator symbol acting on the expression. 33 | /// The result type. 34 | /// The type mapping for the expression. 35 | /// 36 | public PgUnknownBinaryExpression( 37 | SqlExpression left, 38 | SqlExpression right, 39 | string binaryOperator, 40 | Type type, 41 | RelationalTypeMapping? typeMapping = null) 42 | : base(type, typeMapping) 43 | { 44 | Left = Check.NotNull(left, nameof(left)); 45 | Right = Check.NotNull(right, nameof(right)); 46 | Operator = Check.NotEmpty(binaryOperator, nameof(binaryOperator)); 47 | } 48 | 49 | /// 50 | protected override Expression VisitChildren(ExpressionVisitor visitor) 51 | => Update((SqlExpression)visitor.Visit(Left), (SqlExpression)visitor.Visit(Right)); 52 | 53 | /// 54 | /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will 55 | /// return this expression. 56 | /// 57 | public virtual PgUnknownBinaryExpression Update(SqlExpression left, SqlExpression right) 58 | => left == Left && right == Right 59 | ? this 60 | : new PgUnknownBinaryExpression(left, right, Operator, Type, TypeMapping); 61 | 62 | /// 63 | public virtual bool Equals(PgUnknownBinaryExpression? other) 64 | => ReferenceEquals(this, other) 65 | || other is not null && Left.Equals(other.Left) && Right.Equals(other.Right) && Operator == other.Operator; 66 | 67 | /// 68 | public override bool Equals(object? obj) 69 | => obj is PgUnknownBinaryExpression e && Equals(e); 70 | 71 | /// 72 | public override int GetHashCode() 73 | => HashCode.Combine(base.GetHashCode(), Left, Right, Operator); 74 | 75 | /// 76 | protected override void Print(ExpressionPrinter expressionPrinter) 77 | { 78 | expressionPrinter.Visit(Left); 79 | expressionPrinter.Append(Operator); 80 | expressionPrinter.Visit(Right); 81 | } 82 | 83 | /// 84 | public override string ToString() 85 | => $"{Left} {Operator} {Right}"; 86 | } 87 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Expressions/Internal/PgILikeExpression.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; 2 | 3 | /// 4 | /// Represents a PostgreSQL ILIKE expression. 5 | /// 6 | // ReSharper disable once InconsistentNaming 7 | public class PgILikeExpression : SqlExpression, IEquatable 8 | { 9 | /// 10 | /// The match expression. 11 | /// 12 | public virtual SqlExpression Match { get; } 13 | 14 | /// 15 | /// The pattern to match. 16 | /// 17 | public virtual SqlExpression Pattern { get; } 18 | 19 | /// 20 | /// The escape character to use in . 21 | /// 22 | public virtual SqlExpression? EscapeChar { get; } 23 | 24 | /// 25 | /// Constructs a . 26 | /// 27 | /// The expression to match. 28 | /// The pattern to match. 29 | /// The escape character to use in . 30 | /// The associated with the expression. 31 | /// 32 | public PgILikeExpression( 33 | SqlExpression match, 34 | SqlExpression pattern, 35 | SqlExpression? escapeChar, 36 | RelationalTypeMapping? typeMapping) 37 | : base(typeof(bool), typeMapping) 38 | { 39 | Match = match; 40 | Pattern = pattern; 41 | EscapeChar = escapeChar; 42 | } 43 | 44 | /// 45 | protected override Expression VisitChildren(ExpressionVisitor visitor) 46 | => Update( 47 | (SqlExpression)visitor.Visit(Match), 48 | (SqlExpression)visitor.Visit(Pattern), 49 | EscapeChar is null ? null : (SqlExpression)visitor.Visit(EscapeChar)); 50 | 51 | /// 52 | /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will 53 | /// return this expression. 54 | /// 55 | public virtual PgILikeExpression Update( 56 | SqlExpression match, 57 | SqlExpression pattern, 58 | SqlExpression? escapeChar) 59 | => match == Match && pattern == Pattern && escapeChar == EscapeChar 60 | ? this 61 | : new PgILikeExpression(match, pattern, escapeChar, TypeMapping); 62 | 63 | /// 64 | public override bool Equals(object? obj) 65 | => obj is PgILikeExpression other && Equals(other); 66 | 67 | /// 68 | public virtual bool Equals(PgILikeExpression? other) 69 | => ReferenceEquals(this, other) 70 | || other is not null 71 | && base.Equals(other) 72 | && Equals(Match, other.Match) 73 | && Equals(Pattern, other.Pattern) 74 | && Equals(EscapeChar, other.EscapeChar); 75 | 76 | /// 77 | public override int GetHashCode() 78 | => HashCode.Combine(base.GetHashCode(), Match, Pattern, EscapeChar); 79 | 80 | /// 81 | protected override void Print(ExpressionPrinter expressionPrinter) 82 | { 83 | expressionPrinter.Visit(Match); 84 | expressionPrinter.Append(" ILIKE "); 85 | expressionPrinter.Visit(Pattern); 86 | 87 | if (EscapeChar is not null) 88 | { 89 | expressionPrinter.Append(" ESCAPE "); 90 | expressionPrinter.Visit(EscapeChar); 91 | } 92 | } 93 | 94 | /// 95 | public override string ToString() 96 | => $"{Match} ILIKE {Pattern}{(EscapeChar is null ? "" : $" ESCAPE {EscapeChar}")}"; 97 | } 98 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Extensions/GaussDBMigrationBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | 3 | namespace Microsoft.EntityFrameworkCore; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public static class GaussDBMigrationBuilderExtensions 12 | { 13 | /// 14 | /// Returns true if the active provider in a migration is the GaussDB provider. 15 | /// 16 | /// The migrationBuilder from the parameters on 17 | /// 18 | /// or 19 | /// 20 | /// . 21 | /// True if GaussDB is being used; false otherwise. 22 | public static bool IsGaussDB(this MigrationBuilder builder) 23 | => builder.ActiveProvider == typeof(GaussDBMigrationBuilderExtensions).GetTypeInfo().Assembly.GetName().Name; 24 | 25 | /// 26 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 27 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 28 | /// any release. You should only use it directly in your code with extreme caution and knowing that 29 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 30 | /// 31 | public static MigrationBuilder EnsurePostgresExtension( 32 | this MigrationBuilder builder, 33 | string name, 34 | string? schema = null, 35 | string? version = null) 36 | { 37 | Check.NotEmpty(name, nameof(name)); 38 | Check.NullButNotEmpty(schema, nameof(schema)); 39 | Check.NullButNotEmpty(version, nameof(schema)); 40 | 41 | var op = new AlterDatabaseOperation(); 42 | op.GetOrAddPostgresExtension(schema, name, version); 43 | builder.Operations.Add(op); 44 | 45 | return builder; 46 | } 47 | 48 | /// 49 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 50 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 51 | /// any release. You should only use it directly in your code with extreme caution and knowing that 52 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 53 | /// 54 | [Obsolete("Use EnsurePostgresExtension instead")] 55 | public static MigrationBuilder CreatePostgresExtension( 56 | this MigrationBuilder builder, 57 | string name, 58 | string? schema = null, 59 | string? version = null) 60 | => EnsurePostgresExtension(builder, name, schema, version); 61 | 62 | /// 63 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 64 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 65 | /// any release. You should only use it directly in your code with extreme caution and knowing that 66 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 67 | /// 68 | [Obsolete("This no longer does anything and should be removed.")] 69 | public static MigrationBuilder DropPostgresExtension( 70 | this MigrationBuilder builder, 71 | string name) 72 | => builder; 73 | } 74 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBRegconfigTypeMapping.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBRegconfigTypeMapping : GaussDBTypeMapping 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public static GaussDBRegconfigTypeMapping Default { get; } = new(); 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public GaussDBRegconfigTypeMapping() 26 | : base("regconfig", typeof(uint), GaussDBDbType.Regconfig) 27 | { 28 | } 29 | 30 | /// 31 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 32 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 33 | /// any release. You should only use it directly in your code with extreme caution and knowing that 34 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 35 | /// 36 | protected GaussDBRegconfigTypeMapping(RelationalTypeMappingParameters parameters) 37 | : base(parameters, GaussDBDbType.Regconfig) 38 | { 39 | } 40 | 41 | /// 42 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 43 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 44 | /// any release. You should only use it directly in your code with extreme caution and knowing that 45 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 46 | /// 47 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 48 | => new GaussDBRegconfigTypeMapping(parameters); 49 | 50 | /// 51 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 52 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 53 | /// any release. You should only use it directly in your code with extreme caution and knowing that 54 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 55 | /// 56 | protected override string GenerateNonNullSqlLiteral(object value) 57 | => $"'{EscapeSqlLiteral((string)value)}'"; 58 | 59 | private string EscapeSqlLiteral(string literal) 60 | => Check.NotNull(literal, nameof(literal)).Replace("'", "''"); 61 | } 62 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBRegdictionaryTypeMapping.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBRegdictionaryTypeMapping : GaussDBTypeMapping 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public static GaussDBRegdictionaryTypeMapping Default { get; } = new(); 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public GaussDBRegdictionaryTypeMapping() 26 | : base("regdictionary", typeof(uint), GaussDBDbType.Oid) 27 | { 28 | } 29 | 30 | /// 31 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 32 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 33 | /// any release. You should only use it directly in your code with extreme caution and knowing that 34 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 35 | /// 36 | protected GaussDBRegdictionaryTypeMapping(RelationalTypeMappingParameters parameters) 37 | : base(parameters, GaussDBDbType.Oid) 38 | { 39 | } 40 | 41 | /// 42 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 43 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 44 | /// any release. You should only use it directly in your code with extreme caution and knowing that 45 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 46 | /// 47 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 48 | => new GaussDBRegdictionaryTypeMapping(parameters); 49 | 50 | /// 51 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 52 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 53 | /// any release. You should only use it directly in your code with extreme caution and knowing that 54 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 55 | /// 56 | protected override string GenerateNonNullSqlLiteral(object value) 57 | => $"'{EscapeSqlLiteral((string)value)}'"; 58 | 59 | private string EscapeSqlLiteral(string literal) 60 | => Check.NotNull(literal, nameof(literal)).Replace("'", "''"); 61 | } 62 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBRowValueTypeMapping.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 4 | 5 | /// 6 | /// TODO: Update 7 | /// Every node in the SQL tree must have a type mapping, but row values aren't actual values (in the sense that they can be sent as 8 | /// parameters, or have a literal representation). So we have a dummy type mapping for that. 9 | /// 10 | public class GaussDBRowValueTypeMapping : RelationalTypeMapping 11 | { 12 | /// 13 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 14 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 15 | /// any release. You should only use it directly in your code with extreme caution and knowing that 16 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 17 | /// 18 | public GaussDBRowValueTypeMapping(Type clrType) 19 | : base(new RelationalTypeMappingParameters(new CoreTypeMappingParameters(clrType), storeType: "record")) 20 | { 21 | } 22 | 23 | /// 24 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 25 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 26 | /// any release. You should only use it directly in your code with extreme caution and knowing that 27 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 28 | /// 29 | protected GaussDBRowValueTypeMapping(RelationalTypeMappingParameters parameters) 30 | : base(parameters) 31 | { 32 | } 33 | 34 | /// 35 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 36 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 37 | /// any release. You should only use it directly in your code with extreme caution and knowing that 38 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 39 | /// 40 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 41 | => new GaussDBRowValueTypeMapping(parameters); 42 | 43 | /// 44 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 45 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 46 | /// any release. You should only use it directly in your code with extreme caution and knowing that 47 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 48 | /// 49 | // SQL generation for row values is in GaussDBQuerySqlGenerator 50 | protected override string GenerateNonNullSqlLiteral(object value) 51 | => throw new InvalidOperationException("GenerateNonNullSqlLiteral not supported on GaussDBRowValueTypeMapping"); 52 | 53 | /// 54 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 55 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 56 | /// any release. You should only use it directly in your code with extreme caution and knowing that 57 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 58 | /// 59 | protected override void ConfigureParameter(DbParameter parameter) 60 | => throw new InvalidOperationException("ConfigureParameter not supported on GaussDBRowValueTypeMapping"); 61 | } 62 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/ValueGeneration/Internal/GaussDBSequenceHiLoValueGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal; 3 | 4 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.ValueGeneration.Internal; 5 | 6 | /// 7 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 8 | /// directly from your code. This API may change or be removed in future releases. 9 | /// 10 | public class GaussDBSequenceHiLoValueGenerator : HiLoValueGenerator 11 | { 12 | private readonly IRawSqlCommandBuilder _rawSqlCommandBuilder; 13 | private readonly IUpdateSqlGenerator _sqlGenerator; 14 | private readonly IGaussDBRelationalConnection _connection; 15 | private readonly ISequence _sequence; 16 | private readonly IRelationalCommandDiagnosticsLogger _commandLogger; 17 | 18 | /// 19 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 20 | /// directly from your code. This API may change or be removed in future releases. 21 | /// 22 | public GaussDBSequenceHiLoValueGenerator( 23 | IRawSqlCommandBuilder rawSqlCommandBuilder, 24 | IUpdateSqlGenerator sqlGenerator, 25 | GaussDBSequenceValueGeneratorState generatorState, 26 | IGaussDBRelationalConnection connection, 27 | IRelationalCommandDiagnosticsLogger commandLogger) 28 | : base(generatorState) 29 | { 30 | _sequence = generatorState.Sequence; 31 | _rawSqlCommandBuilder = rawSqlCommandBuilder; 32 | _sqlGenerator = sqlGenerator; 33 | _connection = connection; 34 | _commandLogger = commandLogger; 35 | } 36 | 37 | /// 38 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 39 | /// directly from your code. This API may change or be removed in future releases. 40 | /// 41 | protected override long GetNewLowValue() 42 | => (long)Convert.ChangeType( 43 | _rawSqlCommandBuilder 44 | .Build(_sqlGenerator.GenerateNextSequenceValueOperation(_sequence.Name, _sequence.Schema)) 45 | .ExecuteScalar( 46 | new RelationalCommandParameterObject( 47 | _connection, 48 | parameterValues: null, 49 | readerColumns: null, 50 | context: null, 51 | _commandLogger)), 52 | typeof(long), 53 | CultureInfo.InvariantCulture)!; 54 | 55 | /// 56 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 57 | /// directly from your code. This API may change or be removed in future releases. 58 | /// 59 | protected override async Task GetNewLowValueAsync(CancellationToken cancellationToken = default) 60 | => (long)Convert.ChangeType( 61 | await _rawSqlCommandBuilder 62 | .Build(_sqlGenerator.GenerateNextSequenceValueOperation(_sequence.Name, _sequence.Schema)) 63 | .ExecuteScalarAsync( 64 | new RelationalCommandParameterObject( 65 | _connection, 66 | parameterValues: null, 67 | readerColumns: null, 68 | context: null, 69 | _commandLogger), 70 | cancellationToken).ConfigureAwait(false), 71 | typeof(long), 72 | CultureInfo.InvariantCulture)!; 73 | 74 | /// 75 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 76 | /// directly from your code. This API may change or be removed in future releases. 77 | /// 78 | public override bool GeneratesTemporaryValues 79 | => false; 80 | } 81 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBDoubleTypeMapping.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBDoubleTypeMapping : DoubleTypeMapping 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public static new GaussDBDoubleTypeMapping Default { get; } = new(); 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public GaussDBDoubleTypeMapping() 26 | : base("double precision", System.Data.DbType.Double) 27 | { 28 | } 29 | 30 | /// 31 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 32 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 33 | /// any release. You should only use it directly in your code with extreme caution and knowing that 34 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 35 | /// 36 | protected GaussDBDoubleTypeMapping(RelationalTypeMappingParameters parameters) 37 | : base(parameters) 38 | { 39 | } 40 | 41 | /// 42 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 43 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 44 | /// any release. You should only use it directly in your code with extreme caution and knowing that 45 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 46 | /// 47 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 48 | => new GaussDBDoubleTypeMapping(parameters); 49 | 50 | /// 51 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 52 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 53 | /// any release. You should only use it directly in your code with extreme caution and knowing that 54 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 55 | /// 56 | protected override string GenerateNonNullSqlLiteral(object value) 57 | => Convert.ToDouble(value) switch 58 | { 59 | var d when double.IsNaN(d) => "'NaN'", 60 | var d when double.IsPositiveInfinity(d) => "'Infinity'", 61 | var d when double.IsNegativeInfinity(d) => "'-Infinity'", 62 | var d => base.GenerateNonNullSqlLiteral(d) 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/ValueGeneration/Internal/GaussDBSequenceValueGeneratorFactory.cs: -------------------------------------------------------------------------------- 1 | using GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.ValueGeneration.Internal; 4 | 5 | /// 6 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 7 | /// directly from your code. This API may change or be removed in future releases. 8 | /// 9 | public class GaussDBSequenceValueGeneratorFactory : IGaussDBSequenceValueGeneratorFactory 10 | { 11 | private readonly IUpdateSqlGenerator _sqlGenerator; 12 | 13 | /// 14 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 15 | /// directly from your code. This API may change or be removed in future releases. 16 | /// 17 | public GaussDBSequenceValueGeneratorFactory( 18 | IUpdateSqlGenerator sqlGenerator) 19 | { 20 | Check.NotNull(sqlGenerator, nameof(sqlGenerator)); 21 | 22 | _sqlGenerator = sqlGenerator; 23 | } 24 | 25 | /// 26 | /// This API supports the Entity Framework Core infrastructure and is not intended to be used 27 | /// directly from your code. This API may change or be removed in future releases. 28 | /// 29 | public virtual ValueGenerator Create( 30 | IProperty property, 31 | GaussDBSequenceValueGeneratorState generatorState, 32 | IGaussDBRelationalConnection connection, 33 | IRawSqlCommandBuilder rawSqlCommandBuilder, 34 | IRelationalCommandDiagnosticsLogger commandLogger) 35 | { 36 | var type = property.ClrType.UnwrapNullableType().UnwrapEnumType(); 37 | 38 | if (type == typeof(long)) 39 | { 40 | return new GaussDBSequenceHiLoValueGenerator( 41 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 42 | } 43 | 44 | if (type == typeof(int)) 45 | { 46 | return new GaussDBSequenceHiLoValueGenerator( 47 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 48 | } 49 | 50 | if (type == typeof(short)) 51 | { 52 | return new GaussDBSequenceHiLoValueGenerator( 53 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 54 | } 55 | 56 | if (type == typeof(byte)) 57 | { 58 | return new GaussDBSequenceHiLoValueGenerator( 59 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 60 | } 61 | 62 | if (type == typeof(char)) 63 | { 64 | return new GaussDBSequenceHiLoValueGenerator( 65 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 66 | } 67 | 68 | if (type == typeof(ulong)) 69 | { 70 | return new GaussDBSequenceHiLoValueGenerator( 71 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 72 | } 73 | 74 | if (type == typeof(uint)) 75 | { 76 | return new GaussDBSequenceHiLoValueGenerator( 77 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 78 | } 79 | 80 | if (type == typeof(ushort)) 81 | { 82 | return new GaussDBSequenceHiLoValueGenerator( 83 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 84 | } 85 | 86 | if (type == typeof(sbyte)) 87 | { 88 | return new GaussDBSequenceHiLoValueGenerator( 89 | rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); 90 | } 91 | 92 | throw new ArgumentException( 93 | CoreStrings.InvalidValueGeneratorFactoryProperty( 94 | nameof(GaussDBSequenceValueGeneratorFactory), property.Name, property.DeclaringType.DisplayName())); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/Expressions/Internal/PgDeleteExpression.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; 2 | 3 | /// 4 | /// An SQL expression that represents a PostgreSQL DELETE operation. 5 | /// 6 | public sealed class PgDeleteExpression : Expression, IPrintableExpression 7 | { 8 | /// 9 | /// The tables that rows are to be deleted from. 10 | /// 11 | public TableExpression Table { get; } 12 | 13 | /// 14 | /// Additional tables which can be referenced in the predicate. 15 | /// 16 | public IReadOnlyList FromItems { get; } 17 | 18 | /// 19 | /// The WHERE predicate for the DELETE. 20 | /// 21 | public SqlExpression? Predicate { get; } 22 | 23 | /// 24 | /// The list of tags applied to this . 25 | /// 26 | public ISet Tags { get; } 27 | 28 | /// 29 | /// Creates a new instance of the class. 30 | /// 31 | public PgDeleteExpression( 32 | TableExpression table, 33 | IReadOnlyList fromItems, 34 | SqlExpression? predicate, 35 | ISet tags) 36 | { 37 | (Table, FromItems, Predicate, Tags) = (table, fromItems, predicate, tags); 38 | } 39 | 40 | /// 41 | public override Type Type 42 | => typeof(object); 43 | 44 | /// 45 | public override ExpressionType NodeType 46 | => ExpressionType.Extension; 47 | 48 | /// 49 | protected override Expression VisitChildren(ExpressionVisitor visitor) 50 | => Predicate is null 51 | ? this 52 | : Update((SqlExpression?)visitor.Visit(Predicate)); 53 | 54 | /// 55 | /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will 56 | /// return this expression. 57 | /// 58 | /// The property of the result. 59 | public PgDeleteExpression Update(SqlExpression? predicate) 60 | => predicate == Predicate 61 | ? this 62 | : new PgDeleteExpression(Table, FromItems, predicate, Tags); 63 | 64 | /// 65 | public void Print(ExpressionPrinter expressionPrinter) 66 | { 67 | expressionPrinter.AppendLine($"DELETE FROM {Table.Name} AS {Table.Alias}"); 68 | 69 | if (FromItems.Count > 0) 70 | { 71 | var first = true; 72 | foreach (var fromItem in FromItems) 73 | { 74 | if (first) 75 | { 76 | expressionPrinter.Append("USING "); 77 | first = false; 78 | } 79 | else 80 | { 81 | expressionPrinter.Append(", "); 82 | } 83 | 84 | expressionPrinter.Visit(fromItem); 85 | } 86 | } 87 | 88 | if (Predicate is not null) 89 | { 90 | expressionPrinter.Append("WHERE "); 91 | expressionPrinter.Visit(Predicate); 92 | } 93 | } 94 | 95 | /// 96 | public override bool Equals(object? obj) 97 | => obj != null 98 | && (ReferenceEquals(this, obj) 99 | || obj is PgDeleteExpression pgDeleteExpression 100 | && Equals(pgDeleteExpression)); 101 | 102 | private bool Equals(PgDeleteExpression pgDeleteExpression) 103 | => Table == pgDeleteExpression.Table 104 | && FromItems.SequenceEqual(pgDeleteExpression.FromItems) 105 | && (Predicate is null ? pgDeleteExpression.Predicate is null : Predicate.Equals(pgDeleteExpression.Predicate)); 106 | 107 | /// 108 | public override int GetHashCode() 109 | => Table.GetHashCode(); 110 | } 111 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Query/ExpressionTranslators/Internal/GaussDBLikeTranslator.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal; 2 | 3 | /// 4 | /// Translates methods into PostgreSQL LIKE expressions. 5 | /// 6 | public class GaussDBLikeTranslator : IMethodCallTranslator 7 | { 8 | private static readonly MethodInfo Like = 9 | typeof(DbFunctionsExtensions).GetRuntimeMethod( 10 | nameof(DbFunctionsExtensions.Like), 11 | new[] { typeof(DbFunctions), typeof(string), typeof(string) })!; 12 | 13 | private static readonly MethodInfo LikeWithEscape = 14 | typeof(DbFunctionsExtensions).GetRuntimeMethod( 15 | nameof(DbFunctionsExtensions.Like), 16 | new[] { typeof(DbFunctions), typeof(string), typeof(string), typeof(string) })!; 17 | 18 | // ReSharper disable once InconsistentNaming 19 | private static readonly MethodInfo ILike = 20 | typeof(GaussDBDbFunctionsExtensions).GetRuntimeMethod( 21 | nameof(GaussDBDbFunctionsExtensions.ILike), 22 | new[] { typeof(DbFunctions), typeof(string), typeof(string) })!; 23 | 24 | // ReSharper disable once InconsistentNaming 25 | private static readonly MethodInfo ILikeWithEscape = 26 | typeof(GaussDBDbFunctionsExtensions).GetRuntimeMethod( 27 | nameof(GaussDBDbFunctionsExtensions.ILike), 28 | new[] { typeof(DbFunctions), typeof(string), typeof(string), typeof(string) })!; 29 | 30 | private readonly GaussDBSqlExpressionFactory _sqlExpressionFactory; 31 | 32 | /// 33 | /// Initializes a new instance of the class. 34 | /// 35 | /// The SQL expression factory to use when generating expressions.. 36 | public GaussDBLikeTranslator(GaussDBSqlExpressionFactory sqlExpressionFactory) 37 | { 38 | _sqlExpressionFactory = sqlExpressionFactory; 39 | } 40 | 41 | /// 42 | public virtual SqlExpression? Translate( 43 | SqlExpression? instance, 44 | MethodInfo method, 45 | IReadOnlyList arguments, 46 | IDiagnosticsLogger logger) 47 | { 48 | if (method == LikeWithEscape) 49 | { 50 | return _sqlExpressionFactory.Like(arguments[1], arguments[2], arguments[3]); 51 | } 52 | 53 | if (method == ILikeWithEscape) 54 | { 55 | return _sqlExpressionFactory.ILike(arguments[1], arguments[2], arguments[3]); 56 | } 57 | 58 | bool sensitive; 59 | if (method == Like) 60 | { 61 | sensitive = true; 62 | } 63 | else if (method == ILike) 64 | { 65 | sensitive = false; 66 | } 67 | else 68 | { 69 | return null; 70 | } 71 | 72 | // PostgreSQL has backslash as the default LIKE escape character, but EF Core expects 73 | // no escape character unless explicitly requested (https://github.com/aspnet/EntityFramework/issues/8696). 74 | 75 | // If we have a constant expression, we check that there are no backslashes in order to render with 76 | // an ESCAPE clause (better SQL). If we have a constant expression with backslashes or a non-constant 77 | // expression, we render an ESCAPE clause to disable backslash escaping. 78 | 79 | var (match, pattern) = (arguments[1], arguments[2]); 80 | 81 | return pattern switch 82 | { 83 | SqlConstantExpression { Value: string patternValue } when !patternValue.Contains('\\') => sensitive 84 | ? _sqlExpressionFactory.Like(match, pattern, _sqlExpressionFactory.Constant("\\")) 85 | : _sqlExpressionFactory.ILike(match, pattern, _sqlExpressionFactory.Constant("\\")), 86 | _ => sensitive 87 | ? _sqlExpressionFactory.Like(match, pattern, _sqlExpressionFactory.Constant("\\")) 88 | : _sqlExpressionFactory.ILike(match, pattern, _sqlExpressionFactory.Constant("\\")) 89 | }; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBFloatTypeMapping.cs: -------------------------------------------------------------------------------- 1 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 2 | 3 | /// 4 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 5 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 6 | /// any release. You should only use it directly in your code with extreme caution and knowing that 7 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 8 | /// 9 | public class GaussDBFloatTypeMapping : FloatTypeMapping 10 | { 11 | /// 12 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 13 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 14 | /// any release. You should only use it directly in your code with extreme caution and knowing that 15 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 16 | /// 17 | public static new GaussDBFloatTypeMapping Default { get; } = new(); 18 | 19 | /// 20 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 21 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 22 | /// any release. You should only use it directly in your code with extreme caution and knowing that 23 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 24 | /// 25 | public GaussDBFloatTypeMapping() 26 | : base("real", System.Data.DbType.Single) 27 | { 28 | } 29 | 30 | /// 31 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 32 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 33 | /// any release. You should only use it directly in your code with extreme caution and knowing that 34 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 35 | /// 36 | protected GaussDBFloatTypeMapping(RelationalTypeMappingParameters parameters) 37 | : base(parameters) 38 | { 39 | } 40 | 41 | /// 42 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 43 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 44 | /// any release. You should only use it directly in your code with extreme caution and knowing that 45 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 46 | /// 47 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 48 | => new GaussDBFloatTypeMapping(parameters); 49 | 50 | /// 51 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 52 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 53 | /// any release. You should only use it directly in your code with extreme caution and knowing that 54 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 55 | /// 56 | protected override string GenerateNonNullSqlLiteral(object value) 57 | { 58 | var singleValue = Convert.ToSingle(value); 59 | if (double.IsNaN(singleValue)) 60 | { 61 | return "'NaN'"; 62 | } 63 | 64 | if (double.IsPositiveInfinity(singleValue)) 65 | { 66 | return "'Infinity'"; 67 | } 68 | 69 | if (double.IsNegativeInfinity(singleValue)) 70 | { 71 | return "'-Infinity'"; 72 | } 73 | 74 | return base.GenerateNonNullSqlLiteral(singleValue); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBTsQueryTypeMapping.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public class GaussDBTsQueryTypeMapping : GaussDBTypeMapping 12 | { 13 | /// 14 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 15 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 16 | /// any release. You should only use it directly in your code with extreme caution and knowing that 17 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 18 | /// 19 | public static GaussDBTsQueryTypeMapping Default { get; } = new(); 20 | 21 | /// 22 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 23 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 24 | /// any release. You should only use it directly in your code with extreme caution and knowing that 25 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 26 | /// 27 | public GaussDBTsQueryTypeMapping() 28 | : base("tsquery", typeof(GaussDBTsQuery), GaussDBDbType.TsQuery) 29 | { 30 | } 31 | 32 | /// 33 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 34 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 35 | /// any release. You should only use it directly in your code with extreme caution and knowing that 36 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 37 | /// 38 | protected GaussDBTsQueryTypeMapping(RelationalTypeMappingParameters parameters) 39 | : base(parameters, GaussDBDbType.TsQuery) 40 | { 41 | } 42 | 43 | /// 44 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 45 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 46 | /// any release. You should only use it directly in your code with extreme caution and knowing that 47 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 48 | /// 49 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 50 | => new GaussDBTsQueryTypeMapping(parameters); 51 | 52 | /// 53 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 54 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 55 | /// any release. You should only use it directly in your code with extreme caution and knowing that 56 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 57 | /// 58 | protected override string GenerateNonNullSqlLiteral(object value) 59 | { 60 | Check.NotNull(value, nameof(value)); 61 | var query = (GaussDBTsQuery)value; 62 | var builder = new StringBuilder(); 63 | builder.Append("TSQUERY "); 64 | var indexOfFirstQuote = builder.Length - 1; 65 | query.Write(builder); 66 | builder.Replace("'", "''"); 67 | builder[indexOfFirstQuote] = '\''; 68 | builder.Append("'"); 69 | return builder.ToString(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/EFCore.GaussDB/Storage/Internal/Mapping/GaussDBTsVectorMapping.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace GaussDB.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; 4 | 5 | /// 6 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 7 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 8 | /// any release. You should only use it directly in your code with extreme caution and knowing that 9 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 10 | /// 11 | public class GaussDBTsVectorTypeMapping : GaussDBTypeMapping 12 | { 13 | /// 14 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 15 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 16 | /// any release. You should only use it directly in your code with extreme caution and knowing that 17 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 18 | /// 19 | public static GaussDBTsVectorTypeMapping Default { get; } = new(); 20 | 21 | /// 22 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 23 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 24 | /// any release. You should only use it directly in your code with extreme caution and knowing that 25 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 26 | /// 27 | public GaussDBTsVectorTypeMapping() 28 | : base("tsvector", typeof(GaussDBTsVector), GaussDBDbType.TsVector) 29 | { 30 | } 31 | 32 | /// 33 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 34 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 35 | /// any release. You should only use it directly in your code with extreme caution and knowing that 36 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 37 | /// 38 | protected GaussDBTsVectorTypeMapping(RelationalTypeMappingParameters parameters) 39 | : base(parameters, GaussDBDbType.TsVector) 40 | { 41 | } 42 | 43 | /// 44 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 45 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 46 | /// any release. You should only use it directly in your code with extreme caution and knowing that 47 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 48 | /// 49 | protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) 50 | => new GaussDBTsVectorTypeMapping(parameters); 51 | 52 | /// 53 | /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to 54 | /// the same compatibility standards as public APIs. It may be changed or removed without notice in 55 | /// any release. You should only use it directly in your code with extreme caution and knowing that 56 | /// doing so can result in application failures when updating to a new Entity Framework Core release. 57 | /// 58 | protected override string GenerateNonNullSqlLiteral(object value) 59 | { 60 | Check.NotNull(value, nameof(value)); 61 | var vector = (GaussDBTsVector)value; 62 | var builder = new StringBuilder(); 63 | builder.Append("TSVECTOR "); 64 | var indexOfFirstQuote = builder.Length - 1; 65 | builder.Append(vector); 66 | builder.Replace("'", "''"); 67 | builder[indexOfFirstQuote] = '\''; 68 | builder.Append("'"); 69 | return builder.ToString(); 70 | } 71 | } 72 | --------------------------------------------------------------------------------