From db01620aa122e5e1b964f3323a5501f3f6987ab4 Mon Sep 17 00:00:00 2001 From: obimelo Date: Wed, 3 Nov 2021 09:43:11 +0000 Subject: [PATCH] Migration from Core 2 to Core 5 --- src/EFCore.OpenEdge/EFCore.OpenEdge.csproj | 18 +- ...enEdgeDbContextOptionsBuilderExtensions.cs | 22 +- .../OpenEdgeServiceCollectionExtensions.cs | 85 +++++-- .../Internal/OpenEdgeOptionsExtension.cs | 32 ++- .../OpenEdgeRelationalConventionSetBuilder.cs | 10 +- .../OpenEdgeCompositeMemberTranslator.cs | 12 +- .../OpenEdgeCompositeMethodCallTranslator.cs | 11 +- .../OpenEdgeExtractingExpressionVisitor.cs | 62 ++++++ ...dgeParameterExtractingExpressionVisitor.cs | 35 ++- .../Internal/OpenEdgeLoggingDefinitions.cs | 17 ++ .../Internal/OpenEdgeQueryModelGenerator.cs | 44 ++-- .../OpenEdgeQueryTranslationPreprocessor.cs | 26 +++ ...EdgeQueryTranslationPreprocessorFactory.cs | 21 ++ .../Internal/OpenEdgeResultOperatorHandler.cs | 22 +- .../Sql/Internal/OpenEdgeSqlGenerator.cs | 207 +++++++++--------- .../Internal/OpenEdgeSqlGeneratorFactory.cs | 21 +- .../Internal/OpenEdgeCodeGenerator.cs | 5 +- .../Internal/OpenEdgeDatabaseModelFactory.cs | 21 +- .../Internal/OpenEdgeSqlGenerationHelper.cs | 2 - .../Storage/OpenEdgeRelationalConnection.cs | 12 +- .../Update/IOpenEdgeUpdateSqlGenerator.cs | 2 +- ...OpenEdgeModificationCommandBatchFactory.cs | 28 +-- ...penEdgeSingularModificationCommandBatch.cs | 31 +-- .../Update/OpenEdgeUpdateSqlGenerator.cs | 27 +-- 24 files changed, 480 insertions(+), 293 deletions(-) create mode 100644 src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeExtractingExpressionVisitor.cs create mode 100644 src/EFCore.OpenEdge/Query/Internal/OpenEdgeLoggingDefinitions.cs create mode 100644 src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryTranslationPreprocessor.cs create mode 100644 src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryTranslationPreprocessorFactory.cs diff --git a/src/EFCore.OpenEdge/EFCore.OpenEdge.csproj b/src/EFCore.OpenEdge/EFCore.OpenEdge.csproj index c7d8cfa..2e3f1ba 100644 --- a/src/EFCore.OpenEdge/EFCore.OpenEdge.csproj +++ b/src/EFCore.OpenEdge/EFCore.OpenEdge.csproj @@ -1,12 +1,10 @@ - + - netstandard2.0 - EntityFrameworkCore.OpenEdge + net5.0 + EntityFrameworkCore.OpenEdge EntityFrameworkCore.OpenEdge - 7.2 - 1.0.0 - true + true ../../efcoreoe.snk true Alex Wiese @@ -16,7 +14,7 @@ git openedge;progress;Entity Framework Core;entity-framework-core;ef;efcore;orm;sql - + true @@ -28,9 +26,9 @@ - - - + + + diff --git a/src/EFCore.OpenEdge/Extensions/OpenEdgeDbContextOptionsBuilderExtensions.cs b/src/EFCore.OpenEdge/Extensions/OpenEdgeDbContextOptionsBuilderExtensions.cs index 0468bb4..d25f86b 100644 --- a/src/EFCore.OpenEdge/Extensions/OpenEdgeDbContextOptionsBuilderExtensions.cs +++ b/src/EFCore.OpenEdge/Extensions/OpenEdgeDbContextOptionsBuilderExtensions.cs @@ -1,18 +1,15 @@ -using System; -using EntityFrameworkCore.OpenEdge.Infrastructure.Internal; -using Microsoft.EntityFrameworkCore; +using EntityFrameworkCore.OpenEdge.Infrastructure.Internal; using Microsoft.EntityFrameworkCore.Infrastructure; +using System; namespace Microsoft.EntityFrameworkCore { public static class OpenEdgeDbContextOptionsBuilderExtensions { - public static DbContextOptionsBuilder UseOpenEdge( - this DbContextOptionsBuilder optionsBuilder, - string connectionString, - Action optionsAction = null) + public static DbContextOptionsBuilder UseOpenEdge(this DbContextOptionsBuilder optionsBuilder, + string connectionString, + Action optionsAction = null) { - var extension = GetOrCreateExtension(optionsBuilder).WithConnectionString(connectionString); ((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension); @@ -21,10 +18,9 @@ public static DbContextOptionsBuilder UseOpenEdge( return optionsBuilder; } - public static DbContextOptionsBuilder UseOpenEdge( - this DbContextOptionsBuilder optionsBuilder, - string connectionString, - Action optionsAction = null) + public static DbContextOptionsBuilder UseOpenEdge(this DbContextOptionsBuilder optionsBuilder, + string connectionString, + Action optionsAction = null) where TContext : DbContext => (DbContextOptionsBuilder)UseOpenEdge( (DbContextOptionsBuilder)optionsBuilder, connectionString, optionsAction); @@ -32,4 +28,4 @@ public static DbContextOptionsBuilder UseOpenEdge( private static OpenEdgeOptionsExtension GetOrCreateExtension(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.Options.FindExtension() ?? new OpenEdgeOptionsExtension(); } -} \ No newline at end of file +} diff --git a/src/EFCore.OpenEdge/Extensions/OpenEdgeServiceCollectionExtensions.cs b/src/EFCore.OpenEdge/Extensions/OpenEdgeServiceCollectionExtensions.cs index 48cf7f7..7a55e88 100644 --- a/src/EFCore.OpenEdge/Extensions/OpenEdgeServiceCollectionExtensions.cs +++ b/src/EFCore.OpenEdge/Extensions/OpenEdgeServiceCollectionExtensions.cs @@ -8,12 +8,11 @@ using EntityFrameworkCore.OpenEdge.Storage.Internal.Mapping; using EntityFrameworkCore.OpenEdge.Update; using EntityFrameworkCore.OpenEdge.Update.Internal; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; +using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Query; -using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; using Microsoft.EntityFrameworkCore.Query.Internal; -using Microsoft.EntityFrameworkCore.Query.Sql; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Update; using Microsoft.EntityFrameworkCore.Update.Internal; @@ -25,31 +24,91 @@ public static class OpenEdgeServiceCollectionExtensions { public static IServiceCollection AddEntityFrameworkOpenEdge(this IServiceCollection serviceCollection) { +#pragma warning disable EF1001 // Internal EF Core API usage. var builder = new EntityFrameworkRelationalServicesBuilder(serviceCollection) + .TryAdd() +#pragma warning restore EF1001 // Internal EF Core API usage. .TryAdd>() .TryAdd() .TryAdd() .TryAdd() .TryAdd() - .TryAdd() .TryAdd() .TryAdd(p => p.GetService()) - .TryAdd() - .TryAdd() + //.TryAdd() + //.TryAdd() + .TryAdd() - .TryAdd() + /* TESTING */ + + .TryAdd() + .TryAdd() + .TryAdd() + + /* TESTING */ - .TryAdd() - .TryAdd() + + .TryAdd() + .TryAdd() + .TryAdd() .TryAdd() - + .TryAddProviderSpecificServices(b => b .TryAddScoped() - .TryAddScoped()); ; + .TryAddScoped()); builder.TryAddCoreServices(); return serviceCollection; } - } -} \ No newline at end of file +} + + +/* +== FROM EFCore + +public static IServiceCollection AddEntityFrameworkSqlServer(this IServiceCollection serviceCollection) +{ + Check.NotNull(serviceCollection, nameof(serviceCollection)); + + new EntityFrameworkRelationalServicesBuilder(serviceCollection) + .TryAdd() + .TryAdd>() + .TryAdd(p => p.GetRequiredService()) + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd(p => p.GetRequiredService()) + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd(p => p.GetRequiredService()) + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAdd() + .TryAddProviderSpecificServices( + b => b + .TryAddSingleton() + .TryAddSingleton() + .TryAddSingleton() + .TryAddScoped()) + .TryAddCoreServices(); + + return serviceCollection; +} +*/ diff --git a/src/EFCore.OpenEdge/Infrastructure/Internal/OpenEdgeOptionsExtension.cs b/src/EFCore.OpenEdge/Infrastructure/Internal/OpenEdgeOptionsExtension.cs index d75bab0..f6b725c 100644 --- a/src/EFCore.OpenEdge/Infrastructure/Internal/OpenEdgeOptionsExtension.cs +++ b/src/EFCore.OpenEdge/Infrastructure/Internal/OpenEdgeOptionsExtension.cs @@ -1,20 +1,46 @@ using EntityFrameworkCore.OpenEdge.Extensions; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; namespace EntityFrameworkCore.OpenEdge.Infrastructure.Internal { public class OpenEdgeOptionsExtension : RelationalOptionsExtension { + private DbContextOptionsExtensionInfo _info; + + public override DbContextOptionsExtensionInfo Info + { + get + { + return this._info ??= (new OpenEdgeDbContextOptionsExtensionInfo(this)); + } + } + protected override RelationalOptionsExtension Clone() { return new OpenEdgeOptionsExtension(); } - public override bool ApplyServices(IServiceCollection services) + public override void ApplyServices(IServiceCollection services) { services.AddEntityFrameworkOpenEdge(); - return true; + } + + private sealed class OpenEdgeDbContextOptionsExtensionInfo : DbContextOptionsExtensionInfo + { + public OpenEdgeDbContextOptionsExtensionInfo(IDbContextOptionsExtension instance) : + base(instance) + { + } + + public override bool IsDatabaseProvider => true; + + public override string LogFragment => ""; + + public override void PopulateDebugInfo(IDictionary debugInfo) {} + + public override long GetServiceProviderHashCode() => 0; } } -} \ No newline at end of file +} diff --git a/src/EFCore.OpenEdge/Metadata/Conventions/Internal/OpenEdgeRelationalConventionSetBuilder.cs b/src/EFCore.OpenEdge/Metadata/Conventions/Internal/OpenEdgeRelationalConventionSetBuilder.cs index a08d1c6..3743d28 100644 --- a/src/EFCore.OpenEdge/Metadata/Conventions/Internal/OpenEdgeRelationalConventionSetBuilder.cs +++ b/src/EFCore.OpenEdge/Metadata/Conventions/Internal/OpenEdgeRelationalConventionSetBuilder.cs @@ -1,11 +1,13 @@ -using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; +using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; namespace EntityFrameworkCore.OpenEdge.Metadata.Conventions.Internal { - public class OpenEdgeRelationalConventionSetBuilder : RelationalConventionSetBuilder + public class OpenEdgeRelationalConventionSetBuilder : RelationalConventionSetBuilder, IConventionSetBuilder { - public OpenEdgeRelationalConventionSetBuilder(RelationalConventionSetBuilderDependencies dependencies) : base(dependencies) + public OpenEdgeRelationalConventionSetBuilder(ProviderConventionSetBuilderDependencies dependencies, + RelationalConventionSetBuilderDependencies relationalDependencies) : + base(dependencies, relationalDependencies) { } } -} \ No newline at end of file +} diff --git a/src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMemberTranslator.cs b/src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMemberTranslator.cs index 327b5da..9c14b8d 100644 --- a/src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMemberTranslator.cs +++ b/src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMemberTranslator.cs @@ -1,17 +1,19 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; +using Microsoft.EntityFrameworkCore.Query; +//using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; namespace EntityFrameworkCore.OpenEdge.Query.ExpressionTranslators.Internal { - public class OpenEdgeCompositeMemberTranslator : RelationalCompositeMemberTranslator + public class OpenEdgeCompositeMemberTranslator : RelationalMemberTranslatorProvider // RelationalCompositeMemberTranslator { private static readonly List _translatorsMethods = OpenEdgeCompositeMethodCallTranslator.GetTranslatorMethods().ToList(); - public OpenEdgeCompositeMemberTranslator(RelationalCompositeMemberTranslatorDependencies dependencies) - : base(dependencies) - => AddTranslators(_translatorsMethods.Select(type => (IMemberTranslator)Activator.CreateInstance(type))); + public OpenEdgeCompositeMemberTranslator(RelationalMemberTranslatorProviderDependencies dependencies) : base(dependencies) + { + AddTranslators(_translatorsMethods.Select(type => (IMemberTranslator)Activator.CreateInstance(type))); + } } } \ No newline at end of file diff --git a/src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMethodCallTranslator.cs b/src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMethodCallTranslator.cs index 6fc9815..ac76e33 100644 --- a/src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMethodCallTranslator.cs +++ b/src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMethodCallTranslator.cs @@ -2,18 +2,21 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; +using Microsoft.EntityFrameworkCore.Query; +//using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; namespace EntityFrameworkCore.OpenEdge.Query.ExpressionTranslators.Internal { - public class OpenEdgeCompositeMethodCallTranslator : RelationalCompositeMethodCallTranslator + public class OpenEdgeCompositeMethodCallTranslator : RelationalMethodCallTranslatorProvider //RelationalCompositeMethodCallTranslator { private static readonly List _translatorsMethods = GetTranslatorMethods().ToList(); - public OpenEdgeCompositeMethodCallTranslator(RelationalCompositeMethodCallTranslatorDependencies dependencies) + public OpenEdgeCompositeMethodCallTranslator(RelationalMethodCallTranslatorProviderDependencies dependencies) : base(dependencies) - => AddTranslators(_translatorsMethods.Select(type => (IMethodCallTranslator)Activator.CreateInstance(type))); + { + AddTranslators(_translatorsMethods.Select(type => (IMethodCallTranslator)Activator.CreateInstance(type))); + } public static IEnumerable GetTranslatorMethods() => Assembly diff --git a/src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeExtractingExpressionVisitor.cs b/src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeExtractingExpressionVisitor.cs new file mode 100644 index 0000000..c6c46f1 --- /dev/null +++ b/src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeExtractingExpressionVisitor.cs @@ -0,0 +1,62 @@ +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace EntityFrameworkCore.OpenEdge.Query.ExpressionVisitors.Internal +{ + public class OpenEdgeExtractingExpressionVisitor : ExpressionVisitor + { + + protected override Expression VisitNew(NewExpression node) + { + var memberArguments = node.Arguments +#pragma warning disable EF1001 // Internal EF Core API usage. + .Select(m => m is MemberExpression mem ? VisitNewMember(mem) : Visit(m)) +#pragma warning restore EF1001 // Internal EF Core API usage. + .ToList(); + + var newNode = node.Update(memberArguments); + + return newNode; + } + + protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) + { + if (methodCallExpression.Method.Name == "Take") + { + return methodCallExpression; + } + + if (methodCallExpression.Method.Name == "Skip") + { + return methodCallExpression; + } + + return base.VisitMethodCall(methodCallExpression); + } + + protected Expression VisitNewMember(MemberExpression memberExpression) + { + if (memberExpression.Expression is ConstantExpression constant + && constant.Value != null) + { + switch (memberExpression.Member.MemberType) + { + case MemberTypes.Field: + return Expression.Constant(constant.Value.GetType().GetField(memberExpression.Member.Name).GetValue(constant.Value)); + + case MemberTypes.Property: + var propertyInfo = constant.Value.GetType().GetProperty(memberExpression.Member.Name); + if (propertyInfo == null) + { + break; + } + + return Expression.Constant(propertyInfo.GetValue(constant.Value)); + } + } + + return base.VisitMember(memberExpression); + } + } +} diff --git a/src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeParameterExtractingExpressionVisitor.cs b/src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeParameterExtractingExpressionVisitor.cs index 3f1628c..fd39a97 100644 --- a/src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeParameterExtractingExpressionVisitor.cs +++ b/src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeParameterExtractingExpressionVisitor.cs @@ -1,23 +1,32 @@ -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.Internal; -using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; namespace EntityFrameworkCore.OpenEdge.Query.ExpressionVisitors.Internal { +#pragma warning disable EF1001 // Internal EF Core API usage. public class OpenEdgeParameterExtractingExpressionVisitor : ParameterExtractingExpressionVisitor +#pragma warning restore EF1001 // Internal EF Core API usage. { public OpenEdgeParameterExtractingExpressionVisitor(IEvaluatableExpressionFilter evaluatableExpressionFilter, - IParameterValues parameterValues, - IDiagnosticsLogger logger, - DbContext context, - bool parameterize, bool - generateContextAccessors = false) - : base(evaluatableExpressionFilter, parameterValues, logger, context, parameterize, generateContextAccessors) +#pragma warning disable EF1001 // Internal EF Core API usage. + IParameterValues parameterValues, +#pragma warning restore EF1001 // Internal EF Core API usage. + Type contextType, + IModel model, + IDiagnosticsLogger logger, + bool parameterize, +#pragma warning disable EF1001 // Internal EF Core API usage. + bool generateContextAccessors) : + base(evaluatableExpressionFilter, parameterValues, contextType, model, logger, parameterize, generateContextAccessors) +#pragma warning restore EF1001 // Internal EF Core API usage. { } @@ -48,7 +57,9 @@ protected Expression VisitNewMember(MemberExpression memberExpression) protected override Expression VisitNew(NewExpression node) { var memberArguments = node.Arguments +#pragma warning disable EF1001 // Internal EF Core API usage. .Select(m => m is MemberExpression mem ? VisitNewMember(mem) : Visit(m)) +#pragma warning restore EF1001 // Internal EF Core API usage. .ToList(); var newNode = node.Update(memberArguments); diff --git a/src/EFCore.OpenEdge/Query/Internal/OpenEdgeLoggingDefinitions.cs b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeLoggingDefinitions.cs new file mode 100644 index 0000000..a0ca241 --- /dev/null +++ b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeLoggingDefinitions.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore.Diagnostics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameworkCore.OpenEdge.Query.Internal +{ + public class OpenEdgeLoggingDefinitions : RelationalLoggingDefinitions + { + public OpenEdgeLoggingDefinitions() + { + } + } +} + \ No newline at end of file diff --git a/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryModelGenerator.cs b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryModelGenerator.cs index a74fed7..d597378 100644 --- a/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryModelGenerator.cs +++ b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryModelGenerator.cs @@ -3,32 +3,34 @@ using EntityFrameworkCore.OpenEdge.Query.ExpressionVisitors.Internal; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; +using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.Internal; -using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation; +//using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation; namespace EntityFrameworkCore.OpenEdge.Query.Internal { - public class OpenEdgeQueryModelGenerator : QueryModelGenerator - { - private readonly IEvaluatableExpressionFilter _evaluatableExpressionFilter; - private readonly ICurrentDbContext _currentDbContext; + //public class OpenEdgeQueryModelGenerator : QueryModelGenerator + //{ + // private readonly IEvaluatableExpressionFilter _evaluatableExpressionFilter; + // private readonly ICurrentDbContext _currentDbContext; - public OpenEdgeQueryModelGenerator(INodeTypeProviderFactory nodeTypeProviderFactory, - IEvaluatableExpressionFilter evaluatableExpressionFilter, - ICurrentDbContext currentDbContext) - : base(nodeTypeProviderFactory, evaluatableExpressionFilter, currentDbContext) - { - _evaluatableExpressionFilter = evaluatableExpressionFilter; - _currentDbContext = currentDbContext; - } + // public OpenEdgeQueryModelGenerator(INodeTypeProviderFactory nodeTypeProviderFactory, + // IEvaluatableExpressionFilter evaluatableExpressionFilter, + // ICurrentDbContext currentDbContext) + // : base(nodeTypeProviderFactory, evaluatableExpressionFilter, currentDbContext) + // { + // _evaluatableExpressionFilter = evaluatableExpressionFilter; + // _currentDbContext = currentDbContext; + // } - public override Expression ExtractParameters(IDiagnosticsLogger logger, Expression query, IParameterValues parameterValues, - bool parameterize = true, bool generateContextAccessors = false) - { - return new OpenEdgeParameterExtractingExpressionVisitor(_evaluatableExpressionFilter, parameterValues, logger, - _currentDbContext.Context, - parameterize, generateContextAccessors).ExtractParameters(query); - } - } + // public override Expression ExtractParameters(IDiagnosticsLogger logger, Expression query, IParameterValues parameterValues, + // bool parameterize = true, bool generateContextAccessors = false) + // { + // return new OpenEdgeParameterExtractingExpressionVisitor(_evaluatableExpressionFilter, parameterValues, logger, + // _currentDbContext.Context, + // parameterize, generateContextAccessors).ExtractParameters(query); + // } + //} } \ No newline at end of file diff --git a/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryTranslationPreprocessor.cs b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryTranslationPreprocessor.cs new file mode 100644 index 0000000..f8b20d9 --- /dev/null +++ b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryTranslationPreprocessor.cs @@ -0,0 +1,26 @@ +using EntityFrameworkCore.OpenEdge.Query.ExpressionVisitors.Internal; +using Microsoft.EntityFrameworkCore.Query; +using System.Linq.Expressions; + +namespace EntityFrameworkCore.OpenEdge.Query.Internal +{ + public class OpenEdgeQueryTranslationPreprocessor : RelationalQueryTranslationPreprocessor + { + public OpenEdgeQueryTranslationPreprocessor(QueryTranslationPreprocessorDependencies dependencies, + RelationalQueryTranslationPreprocessorDependencies relationalDependencies, + QueryCompilationContext queryCompilationContext) : + base(dependencies, relationalDependencies, queryCompilationContext) + { + + } + + public override Expression Process(Expression query) => base.Process(Preprocess(query)); + + private Expression Preprocess(Expression query) + { + var result = new OpenEdgeExtractingExpressionVisitor().Visit(query); + + return result; + } + } +} diff --git a/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryTranslationPreprocessorFactory.cs b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryTranslationPreprocessorFactory.cs new file mode 100644 index 0000000..886af0e --- /dev/null +++ b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryTranslationPreprocessorFactory.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore.Query; + +namespace EntityFrameworkCore.OpenEdge.Query.Internal +{ + public class OpenEdgeQueryTranslationPreprocessorFactory : IQueryTranslationPreprocessorFactory + { + public OpenEdgeQueryTranslationPreprocessorFactory(QueryTranslationPreprocessorDependencies dependencies, + RelationalQueryTranslationPreprocessorDependencies relationalDependencies) + { + Dependencies = dependencies; + RelationalDependencies = relationalDependencies; + } + + protected QueryTranslationPreprocessorDependencies Dependencies { get; } + + protected RelationalQueryTranslationPreprocessorDependencies RelationalDependencies; + + public QueryTranslationPreprocessor Create(QueryCompilationContext queryCompilationContext) + => new OpenEdgeQueryTranslationPreprocessor(Dependencies, RelationalDependencies, queryCompilationContext); + } +} diff --git a/src/EFCore.OpenEdge/Query/Internal/OpenEdgeResultOperatorHandler.cs b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeResultOperatorHandler.cs index a15aa0a..906d512 100644 --- a/src/EFCore.OpenEdge/Query/Internal/OpenEdgeResultOperatorHandler.cs +++ b/src/EFCore.OpenEdge/Query/Internal/OpenEdgeResultOperatorHandler.cs @@ -1,21 +1,21 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; -using Microsoft.EntityFrameworkCore.Query.Expressions; -using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors; +//using Microsoft.EntityFrameworkCore.Query.Expressions; +//using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors; using Microsoft.EntityFrameworkCore.Query.Internal; namespace EntityFrameworkCore.OpenEdge.Query.Internal { - public class OpenEdgeResultOperatorHandler : RelationalResultOperatorHandler + public class OpenEdgeResultOperatorHandler //: RelationalResultOperatorHandler { - public OpenEdgeResultOperatorHandler(IModel model, - ISqlTranslatingExpressionVisitorFactory sqlTranslatingExpressionVisitorFactory, - ISelectExpressionFactory selectExpressionFactory, - IResultOperatorHandler resultOperatorHandler) - : base(model, sqlTranslatingExpressionVisitorFactory, - selectExpressionFactory, resultOperatorHandler) - { - } + //public OpenEdgeResultOperatorHandler(IModel model, + // ISqlTranslatingExpressionVisitorFactory sqlTranslatingExpressionVisitorFactory, + // ISelectExpressionFactory selectExpressionFactory, + // IResultOperatorHandler resultOperatorHandler) + // : base(model, sqlTranslatingExpressionVisitorFactory, + // selectExpressionFactory, resultOperatorHandler) + //{ + //} } } diff --git a/src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGenerator.cs b/src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGenerator.cs index d73a9f0..4deb56c 100644 --- a/src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGenerator.cs +++ b/src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGenerator.cs @@ -1,112 +1,101 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using EntityFrameworkCore.OpenEdge.Extensions; -using Microsoft.EntityFrameworkCore.Query.Expressions; -using Microsoft.EntityFrameworkCore.Query.Sql; -using Microsoft.EntityFrameworkCore.Storage; - -namespace EntityFrameworkCore.OpenEdge.Query.Sql.Internal -{ - public class OpenEdgeSqlGenerator : DefaultQuerySqlGenerator - { - private bool _existsConditional; - - public OpenEdgeSqlGenerator(QuerySqlGeneratorDependencies dependencies, SelectExpression selectExpression) - : base(dependencies, selectExpression) - { - } - - protected override Expression VisitParameter(ParameterExpression parameterExpression) - { - var parameterName = SqlGenerator.GenerateParameterName(parameterExpression.Name); - - if (Sql.ParameterBuilder.Parameters - .All(p => p.InvariantName != parameterExpression.Name)) - { - var typeMapping - = Dependencies.TypeMappingSource.GetMapping(parameterExpression.Type); - - Sql.AddParameter( - parameterExpression.Name, - parameterName, - typeMapping, - parameterExpression.Type.IsNullableType()); - } - - // Named parameters not supported in the command text - // Need to use '?' instead - Sql.Append("?"); - - return parameterExpression; - } - - protected override Expression VisitConditional(ConditionalExpression conditionalExpression) - { - var visitConditional = base.VisitConditional(conditionalExpression); - - // OpenEdge requires that SELECT statements always include a table, - // so we SELECT from the _File metaschema table that always exists, - // selecting a single row that we know will always exist; the metaschema - // record for the _File metaschema table itself. - if (_existsConditional) - Sql.Append(@" FROM pub.""_File"" f WHERE f.""_File-Name"" = '_File'"); - - _existsConditional = false; - - return visitConditional; - } - - public override Expression VisitExists(ExistsExpression existsExpression) - { - // OpenEdge does not support WHEN EXISTS, only WHERE EXISTS - // We need to SELECT 1 using WHERE EXISTS, then compare - // the result to 1 to satisfy the conditional. - - // OpenEdge requires that SELECT statements always include a table, - // so we SELECT from the _File metaschema table that always exists, - // selecting a single row that we know will always exist; the metaschema - // record for the _File metaschema table itself. - Sql.AppendLine(@"(SELECT 1 FROM pub.""_File"" f WHERE f.""_File-Name"" = '_File' AND EXISTS ("); - - using (Sql.Indent()) - { - Visit(existsExpression.Subquery); - } - - Sql.Append(")) = 1"); - - _existsConditional = true; - - return existsExpression; - } - - protected override void GenerateTop(SelectExpression selectExpression) - { - if (selectExpression.Limit != null - && selectExpression.Offset == null) - { - // OpenEdge doesn't allow braces around the limit - Sql.Append("TOP "); - - Visit(selectExpression.Limit); - - Sql.Append(" "); - } - } - - protected override Expression VisitConstant(ConstantExpression constantExpression) +using EntityFrameworkCore.OpenEdge.Extensions; +using Microsoft.EntityFrameworkCore.Query; +using Microsoft.EntityFrameworkCore.Query.SqlExpressions; +using Microsoft.EntityFrameworkCore.Storage; +using System.Linq; +using System.Linq.Expressions; + +namespace EntityFrameworkCore.OpenEdge.Query.Sql.Internal +{ + public class OpenEdgeSqlGenerator : QuerySqlGenerator + { + private bool _existsConditional; + + public OpenEdgeSqlGenerator(QuerySqlGeneratorDependencies dependencies) : base(dependencies) + { + } + + protected override Expression VisitTable(TableExpression tableExpression) + { + var result = base.VisitTable(tableExpression); + Sql.Append(" WITH (NOLOCK)"); + return result; + } + + protected override Expression VisitParameter(ParameterExpression parameterExpression) + { + var parameterName = Dependencies.SqlGenerationHelper.GenerateParameterName(parameterExpression.Name); + + if (Sql.Parameters.All(p => p.InvariantName != parameterExpression.Name)) + { + var typeMapping = Sql.TypeMappingSource.GetMapping(parameterExpression.Type); + + Sql.AddParameter( + parameterExpression.Name, + parameterName, + typeMapping, + parameterExpression.Type.IsNullableType()); + } + + // Named parameters not supported in the command text + // Need to use '?' instead + Sql.Append("?"); + + return parameterExpression; + } + + protected override Expression VisitConditional(ConditionalExpression conditionalExpression) + { + var visitConditional = base.VisitConditional(conditionalExpression); + + // OpenEdge requires that SELECT statements always include a table, + // so we SELECT from the _File metaschema table that always exists, + // selecting a single row that we know will always exist; the metaschema + // record for the _File metaschema table itself. + if (_existsConditional) + Sql.Append(@" FROM pub.""_File"" f WHERE f.""_File-Name"" = '_File'"); + + _existsConditional = false; + + return visitConditional; + } + + protected override Expression VisitExists(ExistsExpression existsExpression) { - if ((constantExpression.Type == typeof(DateTime) || constantExpression.Type == typeof(DateTime?)) - && constantExpression.Value != null) + // OpenEdge does not support WHEN EXISTS, only WHERE EXISTS + // We need to SELECT 1 using WHERE EXISTS, then compare + // the result to 1 to satisfy the conditional. + + // OpenEdge requires that SELECT statements always include a table, + // so we SELECT from the _File metaschema table that always exists, + // selecting a single row that we know will always exist; the metaschema + // record for the _File metaschema table itself. + Sql.AppendLine(@"(SELECT 1 FROM pub.""_File"" f WHERE f.""_File-Name"" = '_File' AND EXISTS ("); + + using (Sql.Indent()) { - var dateTime = (DateTime)constantExpression.Value; - Sql.Append($"{{ ts '{dateTime:yyyy-MM-dd HH:mm:ss}' }}"); + Visit(existsExpression.Subquery); + } + + Sql.Append(")) = 1"); + + _existsConditional = true; + + return existsExpression; + } + + protected override void GenerateTop(SelectExpression selectExpression) + { + if (selectExpression.Limit != null + && selectExpression.Offset == null) + { + // OpenEdge doesn't allow braces around the limit + Sql.Append("TOP "); + + Visit(selectExpression.Limit); + + Sql.Append(" "); } - else - base.VisitConstant(constantExpression); - - return constantExpression; - } - } -} + } + } +} diff --git a/src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGeneratorFactory.cs b/src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGeneratorFactory.cs index a95f37e..d749a0d 100644 --- a/src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGeneratorFactory.cs +++ b/src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGeneratorFactory.cs @@ -1,17 +1,18 @@ -using Microsoft.EntityFrameworkCore.Query.Expressions; -using Microsoft.EntityFrameworkCore.Query.Sql; +using Microsoft.EntityFrameworkCore.Query; namespace EntityFrameworkCore.OpenEdge.Query.Sql.Internal { - public class OpenEdgeSqlGeneratorFactory : QuerySqlGeneratorFactoryBase + public class OpenEdgeSqlGeneratorFactory : IQuerySqlGeneratorFactory { - public OpenEdgeSqlGeneratorFactory( - QuerySqlGeneratorDependencies dependencies) - : base(dependencies) + public QuerySqlGeneratorDependencies Dependencies { get; } + + public OpenEdgeSqlGeneratorFactory(QuerySqlGeneratorDependencies dependencies) => Dependencies = dependencies; + + public QuerySqlGenerator Create() { - } + var result = new OpenEdgeSqlGenerator(Dependencies); - public override IQuerySqlGenerator CreateDefault(SelectExpression selectExpression) - => new OpenEdgeSqlGenerator(Dependencies, selectExpression); + return result; + } } -} \ No newline at end of file +} diff --git a/src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeCodeGenerator.cs b/src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeCodeGenerator.cs index 37f1d7c..13693d6 100644 --- a/src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeCodeGenerator.cs +++ b/src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeCodeGenerator.cs @@ -1,5 +1,4 @@ -using EntityFrameworkCore.OpenEdge.Extensions; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Scaffolding; @@ -12,7 +11,7 @@ public OpenEdgeCodeGenerator(ProviderCodeGeneratorDependencies dependencies) { } - public override MethodCallCodeFragment GenerateUseProvider(string connectionString) + public override MethodCallCodeFragment GenerateUseProvider(string connectionString, MethodCallCodeFragment providerOptions) { return new MethodCallCodeFragment(nameof(OpenEdgeDbContextOptionsBuilderExtensions.UseOpenEdge), connectionString); } diff --git a/src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeDatabaseModelFactory.cs b/src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeDatabaseModelFactory.cs index 78ed100..0a8731d 100644 --- a/src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeDatabaseModelFactory.cs +++ b/src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeDatabaseModelFactory.cs @@ -1,16 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Data.Odbc; -using System.Linq; -using System.Text; -using EntityFrameworkCore.OpenEdge.Extensions; +using EntityFrameworkCore.OpenEdge.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Scaffolding; using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; +using System; +using System.Data; +using System.Data.Common; +using System.Data.Odbc; +using System.Linq; +using System.Text; namespace EntityFrameworkCore.OpenEdge.Scaffolding.Internal { @@ -24,15 +23,15 @@ public OpenEdgeDatabaseModelFactory(IDiagnosticsLogger tables, IEnumerable schemas) + public DatabaseModel Create(string connectionString, DatabaseModelFactoryOptions options) { using (var connection = new OdbcConnection(connectionString)) { - return Create(connection, tables, schemas); + return Create(connection, options); } } - public DatabaseModel Create(DbConnection connection, IEnumerable tables, IEnumerable schemas) + public DatabaseModel Create(DbConnection connection, DatabaseModelFactoryOptions options) { var databaseModel = new DatabaseModel(); diff --git a/src/EFCore.OpenEdge/Storage/Internal/OpenEdgeSqlGenerationHelper.cs b/src/EFCore.OpenEdge/Storage/Internal/OpenEdgeSqlGenerationHelper.cs index 91265d8..45673f6 100644 --- a/src/EFCore.OpenEdge/Storage/Internal/OpenEdgeSqlGenerationHelper.cs +++ b/src/EFCore.OpenEdge/Storage/Internal/OpenEdgeSqlGenerationHelper.cs @@ -8,12 +8,10 @@ public class OpenEdgeSqlGenerationHelper : RelationalSqlGenerationHelper, IOpenE public OpenEdgeSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies) : base(dependencies) { - } public override string StatementTerminator { get; } = ""; - public override void DelimitIdentifier(StringBuilder builder, string identifier) { // Row ID cannot be delimited in OpenEdge diff --git a/src/EFCore.OpenEdge/Storage/OpenEdgeRelationalConnection.cs b/src/EFCore.OpenEdge/Storage/OpenEdgeRelationalConnection.cs index 2409ac8..5f8d634 100644 --- a/src/EFCore.OpenEdge/Storage/OpenEdgeRelationalConnection.cs +++ b/src/EFCore.OpenEdge/Storage/OpenEdgeRelationalConnection.cs @@ -1,17 +1,15 @@ -using System.Data.Common; +using Microsoft.EntityFrameworkCore.Storage; +using System.Data.Common; using System.Data.Odbc; -using Microsoft.EntityFrameworkCore.Storage; namespace EntityFrameworkCore.OpenEdge.Storage { public class OpenEdgeRelationalConnection : RelationalConnection, IOpenEdgeRelationalConnection { - public OpenEdgeRelationalConnection(RelationalConnectionDependencies dependencies) - : base(dependencies) + public OpenEdgeRelationalConnection(RelationalConnectionDependencies dependencies) : base(dependencies) { } - protected override DbConnection CreateDbConnection() - => new OdbcConnection(ConnectionString); + protected override DbConnection CreateDbConnection() => new OdbcConnection(ConnectionString); } -} \ No newline at end of file +} diff --git a/src/EFCore.OpenEdge/Update/IOpenEdgeUpdateSqlGenerator.cs b/src/EFCore.OpenEdge/Update/IOpenEdgeUpdateSqlGenerator.cs index 88a9856..6f2606d 100644 --- a/src/EFCore.OpenEdge/Update/IOpenEdgeUpdateSqlGenerator.cs +++ b/src/EFCore.OpenEdge/Update/IOpenEdgeUpdateSqlGenerator.cs @@ -2,7 +2,7 @@ namespace EntityFrameworkCore.OpenEdge.Update { - public interface IOpenEdgeUpdateSqlGenerator :IUpdateSqlGenerator + public interface IOpenEdgeUpdateSqlGenerator : IUpdateSqlGenerator { } } \ No newline at end of file diff --git a/src/EFCore.OpenEdge/Update/Internal/OpenEdgeModificationCommandBatchFactory.cs b/src/EFCore.OpenEdge/Update/Internal/OpenEdgeModificationCommandBatchFactory.cs index a4a3708..84c5cea 100644 --- a/src/EFCore.OpenEdge/Update/Internal/OpenEdgeModificationCommandBatchFactory.cs +++ b/src/EFCore.OpenEdge/Update/Internal/OpenEdgeModificationCommandBatchFactory.cs @@ -1,32 +1,16 @@ -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Update; +using Microsoft.EntityFrameworkCore.Update; namespace EntityFrameworkCore.OpenEdge.Update.Internal { public class OpenEdgeModificationCommandBatchFactory : IModificationCommandBatchFactory { - private readonly IRelationalCommandBuilderFactory _commandBuilderFactory; - private readonly ISqlGenerationHelper _sqlGenerationHelper; - private readonly IRelationalValueBufferFactoryFactory _valueBufferFactoryFactory; - private readonly IDbContextOptions _options; - private readonly IUpdateSqlGenerator _updateSqlGenerator; + private readonly ModificationCommandBatchFactoryDependencies _dependencies; - public OpenEdgeModificationCommandBatchFactory(IRelationalCommandBuilderFactory commandBuilderFactory, ISqlGenerationHelper sqlGenerationHelper, - IUpdateSqlGenerator updateSqlGenerator, IRelationalValueBufferFactoryFactory valueBufferFactoryFactory, IDbContextOptions options) + public OpenEdgeModificationCommandBatchFactory(ModificationCommandBatchFactoryDependencies dependencies) { - _commandBuilderFactory = commandBuilderFactory; - _sqlGenerationHelper = sqlGenerationHelper; - _updateSqlGenerator = updateSqlGenerator; - _valueBufferFactoryFactory = valueBufferFactoryFactory; - _options = options; + _dependencies = dependencies; } - public virtual ModificationCommandBatch Create() - => new OpenEdgeSingularModificationCommandBatch( - _commandBuilderFactory, - _sqlGenerationHelper, - _updateSqlGenerator, - _valueBufferFactoryFactory); + public virtual ModificationCommandBatch Create() => new OpenEdgeSingularModificationCommandBatch(_dependencies); } -} \ No newline at end of file +} diff --git a/src/EFCore.OpenEdge/Update/OpenEdgeSingularModificationCommandBatch.cs b/src/EFCore.OpenEdge/Update/OpenEdgeSingularModificationCommandBatch.cs index e04e34e..db3d841 100644 --- a/src/EFCore.OpenEdge/Update/OpenEdgeSingularModificationCommandBatch.cs +++ b/src/EFCore.OpenEdge/Update/OpenEdgeSingularModificationCommandBatch.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Update; +using System.Collections.Generic; +using System.Linq; namespace EntityFrameworkCore.OpenEdge.Update { @@ -9,16 +9,15 @@ public class OpenEdgeSingularModificationCommandBatch : SingularModificationComm { private readonly IRelationalCommandBuilderFactory _commandBuilderFactory; - public OpenEdgeSingularModificationCommandBatch(IRelationalCommandBuilderFactory commandBuilderFactory, ISqlGenerationHelper sqlGenerationHelper, IUpdateSqlGenerator updateSqlGenerator, IRelationalValueBufferFactoryFactory valueBufferFactoryFactory) : base(commandBuilderFactory, sqlGenerationHelper, updateSqlGenerator, valueBufferFactoryFactory) + public OpenEdgeSingularModificationCommandBatch(ModificationCommandBatchFactoryDependencies dependencies) : base(dependencies) { - _commandBuilderFactory = commandBuilderFactory; + _commandBuilderFactory = dependencies.CommandBuilderFactory; } protected override RawSqlCommand CreateStoreCommand() { - var commandBuilder = _commandBuilderFactory - .Create() - .Append(GetCommandText()); + var commandBuilder = _commandBuilderFactory.Create() + .Append(GetCommandText()); var parameterValues = new Dictionary(GetParameterCount()); @@ -31,18 +30,22 @@ protected override RawSqlCommand CreateStoreCommand() { if (columnModification.UseCurrentValueParameter) { - commandBuilder.AddParameter(columnModification.ParameterName, - SqlGenerationHelper.GenerateParameterName(columnModification.ParameterName), - columnModification.Property); + commandBuilder.AddParameter( + columnModification.ParameterName, + Dependencies.SqlGenerationHelper.GenerateParameterName(columnModification.ParameterName), + columnModification.TypeMapping, + columnModification.IsNullable); parameterValues.Add(columnModification.ParameterName, columnModification.Value); } if (columnModification.UseOriginalValueParameter) { - commandBuilder.AddParameter(columnModification.OriginalParameterName, - SqlGenerationHelper.GenerateParameterName(columnModification.OriginalParameterName), - columnModification.Property); + commandBuilder.AddParameter( + columnModification.OriginalParameterName, + Dependencies.SqlGenerationHelper.GenerateParameterName(columnModification.OriginalParameterName), + columnModification.TypeMapping, + columnModification.IsNullable); parameterValues.Add(columnModification.OriginalParameterName, columnModification.OriginalValue); } diff --git a/src/EFCore.OpenEdge/Update/OpenEdgeUpdateSqlGenerator.cs b/src/EFCore.OpenEdge/Update/OpenEdgeUpdateSqlGenerator.cs index b03edcd..31d16b0 100644 --- a/src/EFCore.OpenEdge/Update/OpenEdgeUpdateSqlGenerator.cs +++ b/src/EFCore.OpenEdge/Update/OpenEdgeUpdateSqlGenerator.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Text; -using EntityFrameworkCore.OpenEdge.Extensions; +using EntityFrameworkCore.OpenEdge.Extensions; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Update; +using System.Collections.Generic; +using System.Linq; +using System.Text; namespace EntityFrameworkCore.OpenEdge.Update { @@ -29,8 +26,7 @@ protected override void AppendIdentityWhereCondition(StringBuilder commandString .Append("1 = 1"); } - - protected override void AppendValues(StringBuilder commandStringBuilder, IReadOnlyList operations) + protected override void AppendValues(StringBuilder commandStringBuilder, string name, string schema, IReadOnlyList operations) { bool useLiterals = true; @@ -73,8 +69,7 @@ private void AppendSqlLiteral(StringBuilder commandStringBuilder, object value, } - protected override void AppendUpdateCommandHeader(StringBuilder commandStringBuilder, string name, string schema, - IReadOnlyList operations) + protected override void AppendUpdateCommandHeader(StringBuilder commandStringBuilder, string name, string schema, IReadOnlyList operations) { commandStringBuilder.Append("UPDATE "); SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, name, schema); @@ -97,8 +92,7 @@ protected override void AppendUpdateCommandHeader(StringBuilder commandStringBui }); } - protected override void AppendWhereCondition(StringBuilder commandStringBuilder, ColumnModification columnModification, - bool useOriginalValue) + protected override void AppendWhereCondition(StringBuilder commandStringBuilder, ColumnModification columnModification, bool useOriginalValue) { SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, columnModification.ColumnName); @@ -125,10 +119,8 @@ protected override void AppendWhereCondition(StringBuilder commandStringBuilder, } } - public override ResultSetMapping AppendInsertOperation(StringBuilder commandStringBuilder, ModificationCommand command, - int commandPosition) + public override ResultSetMapping AppendInsertOperation(StringBuilder commandStringBuilder, ModificationCommand command, int commandPosition) { - var name = command.TableName; var schema = command.Schema; var operations = command.ColumnModifications; @@ -142,8 +134,7 @@ public override ResultSetMapping AppendInsertOperation(StringBuilder commandStri return ResultSetMapping.NoResultSet; } - public override ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, ModificationCommand command, - int commandPosition) + public override ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, ModificationCommand command, int commandPosition) { var name = command.TableName; var schema = command.Schema;