diff --git a/src/EFCore.Cosmos/Query/Internal/CollectionShaperExpression.cs b/src/EFCore.Cosmos/Query/Internal/CollectionShaperExpression.cs new file mode 100644 index 00000000000..3b618c142ef --- /dev/null +++ b/src/EFCore.Cosmos/Query/Internal/CollectionShaperExpression.cs @@ -0,0 +1,146 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Utilities; + +namespace Microsoft.EntityFrameworkCore.Query +{ + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public class CollectionShaperExpression : Expression, IPrintableExpression + { + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public CollectionShaperExpression( + Expression projection, + Expression innerShaper, + INavigationBase? navigation, + Type elementType) + { + Check.NotNull(projection, nameof(projection)); + Check.NotNull(innerShaper, nameof(innerShaper)); + + Projection = projection; + InnerShaper = innerShaper; + Navigation = navigation; + ElementType = elementType; + } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual Expression Projection { get; } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual Expression InnerShaper { get; } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual INavigationBase? Navigation { get; } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual Type ElementType { get; } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public sealed override ExpressionType NodeType + => ExpressionType.Extension; + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public override Type Type + => Navigation?.ClrType ?? typeof(List<>).MakeGenericType(ElementType); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + protected override Expression VisitChildren(ExpressionVisitor visitor) + { + Check.NotNull(visitor, nameof(visitor)); + + var projection = visitor.Visit(Projection); + var innerShaper = visitor.Visit(InnerShaper); + + return Update(projection, innerShaper); + } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual CollectionShaperExpression Update( + Expression projection, + Expression innerShaper) + { + Check.NotNull(projection, nameof(projection)); + Check.NotNull(innerShaper, nameof(innerShaper)); + + return projection != Projection || innerShaper != InnerShaper + ? new CollectionShaperExpression(projection, innerShaper, Navigation, ElementType) + : this; + } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) + { + Check.NotNull(expressionPrinter, nameof(expressionPrinter)); + + expressionPrinter.AppendLine("CollectionShaper:"); + using (expressionPrinter.Indent()) + { + expressionPrinter.Append("("); + expressionPrinter.Visit(Projection); + expressionPrinter.Append(", "); + expressionPrinter.Visit(InnerShaper); + expressionPrinter.AppendLine($", {Navigation?.Name})"); + } + } + } +} diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs index ba5333cb157..153e60dc180 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs @@ -37,18 +37,10 @@ private static readonly MethodInfo _getParameterValueMethodInfo private SelectExpression _selectExpression; private bool _clientEval; - private readonly IDictionary _projectionMapping - = new Dictionary(); - + private readonly Dictionary _projectionMapping = new(); private readonly Stack _projectionMembers = new(); - -#pragma warning disable CS0618 // Type or member is obsolete - private readonly IDictionary _collectionShaperMapping - = new Dictionary(); -#pragma warning restore CS0618 // Type or member is obsolete - - private readonly Stack _includedNavigations - = new(); + private readonly Dictionary _collectionShaperMapping = new(); + private readonly Stack _includedNavigations = new(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs index c1b9cbe0c81..25ff914a0d5 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs @@ -227,31 +227,6 @@ public override ShapedQueryExpression TranslateSubquery(Expression expression) throw new InvalidOperationException(CoreStrings.TranslationFailed(expression.Print())); } - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - [Obsolete("Use overload which takes IEntityType.")] - protected override ShapedQueryExpression CreateShapedQueryExpression(Type elementType) - { - Check.NotNull(elementType, nameof(elementType)); - - var entityType = _queryCompilationContext.Model.FindEntityType(elementType); - var selectExpression = _sqlExpressionFactory.Select(entityType); - - return new ShapedQueryExpression( - selectExpression, - new EntityShaperExpression( - entityType, - new ProjectionBindingExpression( - selectExpression, - new ProjectionMember(), - typeof(ValueBuffer)), - false)); - } - /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index 5b10b4e372c..9fa4cda167b 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -115,21 +115,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp return base.VisitMethodCall(methodCallExpression); } - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - [Obsolete("Use overload which takes IEntityType.")] - protected override ShapedQueryExpression CreateShapedQueryExpression(Type elementType) - { - Check.NotNull(elementType, nameof(elementType)); - - // Let it throw if null found. - return CreateShapedQueryExpression(_model.FindEntityType(elementType)!); - } - /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore.Relational/Query/EntityProjectionExpression.cs b/src/EFCore.Relational/Query/EntityProjectionExpression.cs index 060174ef040..5d34792ec49 100644 --- a/src/EFCore.Relational/Query/EntityProjectionExpression.cs +++ b/src/EFCore.Relational/Query/EntityProjectionExpression.cs @@ -27,18 +27,6 @@ public class EntityProjectionExpression : Expression private readonly IReadOnlyDictionary _propertyExpressionMap; private readonly Dictionary _ownedNavigationMap = new(); - /// - /// Creates a new instance of the class. - /// - /// The entity type to shape. - /// The table from which entity columns are being projected out. - /// A bool value indicating whether this entity instance can be null. - [Obsolete("Use the constructor which takes populated column expressions map.", error: true)] - public EntityProjectionExpression(IEntityType entityType, TableExpressionBase innerTable, bool nullable) - { - throw new NotSupportedException("Obsolete: Use the constructor which takes populated column expressions map."); - } - /// /// Creates a new instance of the class. /// diff --git a/src/EFCore.Relational/Query/ISqlExpressionFactory.cs b/src/EFCore.Relational/Query/ISqlExpressionFactory.cs index 8cbccfafc77..c355b280fbc 100644 --- a/src/EFCore.Relational/Query/ISqlExpressionFactory.cs +++ b/src/EFCore.Relational/Query/ISqlExpressionFactory.cs @@ -23,22 +23,6 @@ namespace Microsoft.EntityFrameworkCore.Query /// public interface ISqlExpressionFactory { - /// - /// Gets the relational database type for a given object, throwing if no mapping is found. - /// - /// The object to get the mapping for. - /// The type mapping to be used. - [Obsolete("Use IRelationalTypeMappingSource directly.")] - RelationalTypeMapping GetTypeMappingForValue(object? value); - - /// - /// Finds the type mapping for a given . - /// - /// The CLR type. - /// The type mapping, or if none was found. - [Obsolete("Use IRelationalTypeMappingSource directly.")] - RelationalTypeMapping? FindMapping(Type type); - /// /// Applies type mapping to the given . /// @@ -289,15 +273,6 @@ SqlUnaryExpression Convert( /// An expression representing a negation operation in a SQL tree. SqlUnaryExpression Negate(SqlExpression operand); - /// - /// Creates a new which represent a CASE statement in a SQL tree. - /// - /// An expression to compare with in . - /// A list of to compare and get result from. - /// An expression representing a CASE statement in a SQL tree. - [Obsolete("Use overload which takes IReadOnlyList instead of params")] - CaseExpression Case(SqlExpression operand, params CaseWhenClause[] whenClauses); - /// /// Creates a new which represent a CASE statement in a SQL tree. /// @@ -318,99 +293,6 @@ CaseExpression Case( /// An expression representing a CASE statement in a SQL tree. CaseExpression Case(IReadOnlyList whenClauses, SqlExpression? elseResult); - /// - /// Creates a new which represents a function call in a SQL tree. - /// - /// The name of the function. - /// The arguments of the function. - /// The of the expression. - /// The associated with the expression. - /// An expression representing a function call in a SQL tree. - [Obsolete("Use overload that explicitly specifies value for 'argumentsPropagateNullability' argument.")] - SqlFunctionExpression Function( - string name, - IEnumerable arguments, - Type returnType, - RelationalTypeMapping? typeMapping = null); - - /// - /// Creates a new which represents a function call in a SQL tree. - /// - /// The schema in which the function is defined. - /// The name of the function. - /// The arguments of the function. - /// The of the expression. - /// The associated with the expression. - /// An expression representing a function call in a SQL tree. - [Obsolete("Use overload that explicitly specifies value for 'argumentsPropagateNullability' argument.")] - SqlFunctionExpression Function( - string? schema, - string name, - IEnumerable arguments, - Type returnType, - RelationalTypeMapping? typeMapping = null); - - /// - /// Creates a new which represents a function call in a SQL tree. - /// - /// An expression on which the function is applied. - /// The name of the function. - /// The arguments of the function. - /// The of the expression. - /// The associated with the expression. - /// An expression representing a function call in a SQL tree. - [Obsolete( - "Use overload that explicitly specifies value for 'instancePropagatesNullability' and 'argumentsPropagateNullability' arguments.")] - SqlFunctionExpression Function( - SqlExpression instance, - string name, - IEnumerable arguments, - Type returnType, - RelationalTypeMapping? typeMapping = null); - - /// - /// Creates a new which represents a function call in a SQL tree. - /// - /// The name of the function. - /// The of the expression. - /// The associated with the expression. - /// An expression representing a function call in a SQL tree. - [Obsolete("Use NiladicFunction method.")] - SqlFunctionExpression Function( - string name, - Type returnType, - RelationalTypeMapping? typeMapping = null); - - /// - /// Creates a new which represents a function call in a SQL tree. - /// - /// The schema in which the function is defined. - /// The name of the function. - /// The of the expression. - /// The associated with the expression. - /// An expression representing a function call in a SQL tree. - [Obsolete("Use NiladicFunction method.")] - SqlFunctionExpression Function( - string schema, - string name, - Type returnType, - RelationalTypeMapping? typeMapping = null); - - /// - /// Creates a new which represents a function call in a SQL tree. - /// - /// An expression on which the function is applied. - /// The name of the function. - /// The of the expression. - /// The associated with the expression. - /// An expression representing a function call in a SQL tree. - [Obsolete("Use NiladicFunction method.")] - SqlFunctionExpression Function( - SqlExpression instance, - string name, - Type returnType, - RelationalTypeMapping? typeMapping = null); - /// /// Creates a new which represents a function call in a SQL tree. /// @@ -593,16 +475,5 @@ SqlFunctionExpression NiladicFunction( /// A table source to project from. /// An expression representing a SELECT in a SQL tree. SelectExpression Select(IEntityType entityType, TableExpressionBase tableExpressionBase); - - /// - /// Creates a new which represents a SELECT in a SQL tree projecting an entity type from - /// a table source created using a custom SQL. - /// - /// An entity type to project. - /// A custom SQL for the table source. - /// An expression representing parameters passed to the custom SQL. - /// An expression representing a SELECT in a SQL tree. - [Obsolete("Use overload which takes TableExpressionBase by passing FromSqlExpression directly.")] - SelectExpression Select(IEntityType entityType, string sql, Expression sqlArguments); } } diff --git a/src/EFCore.Relational/Query/QuerySqlGenerator.cs b/src/EFCore.Relational/Query/QuerySqlGenerator.cs index bb86d1a71cd..e106da74a73 100644 --- a/src/EFCore.Relational/Query/QuerySqlGenerator.cs +++ b/src/EFCore.Relational/Query/QuerySqlGenerator.cs @@ -844,19 +844,6 @@ protected override Expression VisitIn(InExpression inExpression) return inExpression; } - /// - /// Generates a SQL operator for a SQL binary operation. - /// - /// A SQL binary operation. - /// A string representation of the binary operator. - [Obsolete("Use GetOperator instead.")] - protected virtual string GenerateOperator(SqlBinaryExpression binaryExpression) - { - Check.NotNull(binaryExpression, nameof(binaryExpression)); - - return _operatorMap[binaryExpression.OperatorType]; - } - /// /// Gets a SQL operator for a SQL binary operation. /// diff --git a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs index ea3c739ae00..f8b64f1dda3 100644 --- a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs @@ -25,32 +25,6 @@ public class RelationalCollectionShaperExpression : Expression, IPrintableExpres /// /// Creates a new instance of the class. /// - /// A unique id for the collection being shaped. - /// An identifier for the parent element. - /// An identifier for the outer element. - /// An identifier for the element in the collection. - /// An expression used to create individual elements of the collection. - /// A navigation associated with this collection, if any. - /// The clr type of individual elements in the collection. - [Obsolete("Use ctor which takes value comparers.")] - public RelationalCollectionShaperExpression( - int collectionId, - Expression parentIdentifier, - Expression outerIdentifier, - Expression selfIdentifier, - Expression innerShaper, - INavigation? navigation, - Type elementType) - : this( - collectionId, parentIdentifier, outerIdentifier, selfIdentifier, - null, null, null, innerShaper, navigation, elementType) - { - } - - /// - /// Creates a new instance of the class. - /// - /// A unique id for the collection being shaped. /// An identifier for the parent element. /// An identifier for the outer element. /// An identifier for the element in the collection. @@ -60,9 +34,7 @@ public RelationalCollectionShaperExpression( /// An expression used to create individual elements of the collection. /// A navigation associated with this collection, if any. /// The clr type of individual elements in the collection. - [Obsolete("Use ctor without collectionId")] public RelationalCollectionShaperExpression( - int collectionId, Expression parentIdentifier, Expression outerIdentifier, Expression selfIdentifier, @@ -79,7 +51,6 @@ public RelationalCollectionShaperExpression( Check.NotNull(innerShaper, nameof(innerShaper)); Check.NotNull(elementType, nameof(elementType)); - CollectionId = collectionId; ParentIdentifier = parentIdentifier; OuterIdentifier = outerIdentifier; SelfIdentifier = selfIdentifier; @@ -91,52 +62,6 @@ public RelationalCollectionShaperExpression( ElementType = elementType; } - /// - /// Creates a new instance of the class. - /// - /// An identifier for the parent element. - /// An identifier for the outer element. - /// An identifier for the element in the collection. - /// A list of value comparers to compare parent identifier. - /// A list of value comparers to compare outer identifier. - /// A list of value comparers to compare self identifier. - /// An expression used to create individual elements of the collection. - /// A navigation associated with this collection, if any. - /// The clr type of individual elements in the collection. - public RelationalCollectionShaperExpression( - Expression parentIdentifier, - Expression outerIdentifier, - Expression selfIdentifier, - IReadOnlyList? parentIdentifierValueComparers, - IReadOnlyList? outerIdentifierValueComparers, - IReadOnlyList? selfIdentifierValueComparers, - Expression innerShaper, - INavigationBase? navigation, - Type elementType) - { - Check.NotNull(parentIdentifier, nameof(parentIdentifier)); - Check.NotNull(outerIdentifier, nameof(outerIdentifier)); - Check.NotNull(selfIdentifier, nameof(selfIdentifier)); - Check.NotNull(innerShaper, nameof(innerShaper)); - Check.NotNull(elementType, nameof(elementType)); - - ParentIdentifier = parentIdentifier; - OuterIdentifier = outerIdentifier; - SelfIdentifier = selfIdentifier; - ParentIdentifierValueComparers = parentIdentifierValueComparers; - OuterIdentifierValueComparers = outerIdentifierValueComparers; - SelfIdentifierValueComparers = selfIdentifierValueComparers; - InnerShaper = innerShaper; - Navigation = navigation; - ElementType = elementType; - } - - /// - /// A unique id for this collection shaper. - /// - [Obsolete("CollectionId are not stored in shaper anymore. Shaper compiler assigns it as needed.")] - public virtual int CollectionId { get; } - /// /// The identifier for the parent element. /// diff --git a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs index 43bbcd08230..37a4774d1c0 100644 --- a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs @@ -154,11 +154,6 @@ public override EntityShaperExpression WithEntityType(IEntityType entityType) : this; } - /// - [Obsolete("Use MakeNullable() instead.")] - public override EntityShaperExpression MarkAsNullable() - => MakeNullable(); - /// public override EntityShaperExpression MakeNullable(bool nullable = true) { diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs index eeef9eb3f86..d8e62b26e34 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs @@ -57,25 +57,9 @@ public override Expression Process(Expression query) .Visit(query); query = new RelationalValueConverterCompensatingExpressionVisitor(RelationalDependencies.SqlExpressionFactory).Visit(query); -#pragma warning disable 618 - query = OptimizeSqlExpression(query); -#pragma warning restore 618 - return query; } - /// - /// Optimizes the SQL expression. - /// - /// An expression to optimize. - /// An expression which has SQL optimized. - [Obsolete( - "Use 'Optimize' method on " - + nameof(RelationalParameterBasedSqlProcessor) - + " instead. If you have a case for optimizations to be performed here, please file an issue on github.com/dotnet/efcore.")] - protected virtual Expression OptimizeSqlExpression(Expression query) - => query; - private sealed class TableAliasVerifyingExpressionVisitor : ExpressionVisitor { private readonly ScopedVisitor _scopedVisitor = new(); diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index 9adff93a033..15f37061080 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -170,18 +170,6 @@ when queryRootExpression.EntityType.GetSqlQueryMappings().FirstOrDefault(m => m. protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor() => new RelationalQueryableMethodTranslatingExpressionVisitor(this); - /// - [Obsolete("Use overload which takes IEntityType.")] - protected override ShapedQueryExpression CreateShapedQueryExpression(Type elementType) - { - Check.NotNull(elementType, nameof(elementType)); - - var entityType = _queryCompilationContext.Model.FindEntityType(elementType)!; - var queryExpression = _sqlExpressionFactory.Select(entityType); - - return CreateShapedQueryExpression(entityType, queryExpression); - } - /// protected override ShapedQueryExpression CreateShapedQueryExpression(IEntityType entityType) { diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs index 2949592bf11..ab33f264eeb 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs @@ -53,20 +53,12 @@ public sealed record RelationalShapedQueryCompilingExpressionVisitorDependencies [EntityFrameworkInternal] public RelationalShapedQueryCompilingExpressionVisitorDependencies( IQuerySqlGeneratorFactory querySqlGeneratorFactory, - ISqlExpressionFactory sqlExpressionFactory, - IParameterNameGeneratorFactory parameterNameGeneratorFactory, IRelationalParameterBasedSqlProcessorFactory relationalParameterBasedSqlProcessorFactory) { Check.NotNull(querySqlGeneratorFactory, nameof(querySqlGeneratorFactory)); - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); - Check.NotNull(parameterNameGeneratorFactory, nameof(parameterNameGeneratorFactory)); Check.NotNull(relationalParameterBasedSqlProcessorFactory, nameof(relationalParameterBasedSqlProcessorFactory)); QuerySqlGeneratorFactory = querySqlGeneratorFactory; -#pragma warning disable CS0618 // Type or member is obsolete - SqlExpressionFactory = sqlExpressionFactory; - ParameterNameGeneratorFactory = parameterNameGeneratorFactory; -#pragma warning restore CS0618 // Type or member is obsolete RelationalParameterBasedSqlProcessorFactory = relationalParameterBasedSqlProcessorFactory; } @@ -75,18 +67,6 @@ public RelationalShapedQueryCompilingExpressionVisitorDependencies( /// public IQuerySqlGeneratorFactory QuerySqlGeneratorFactory { get; init; } - /// - /// The SQL expression factory. - /// - [Obsolete("Use the service from " + nameof(RelationalParameterBasedSqlProcessorDependencies) + ".")] - public ISqlExpressionFactory SqlExpressionFactory { get; init; } - - /// - /// The parameter name-generator factory. - /// - [Obsolete("Use the service from " + nameof(RelationalParameterBasedSqlProcessorDependencies) + ".")] - public IParameterNameGeneratorFactory ParameterNameGeneratorFactory { get; init; } - /// /// The SQL processor based on parameter values. /// diff --git a/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs b/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs index 9afaca79c14..c02f9aa3613 100644 --- a/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs @@ -26,7 +26,6 @@ public class RelationalSplitCollectionShaperExpression : Expression, IPrintableE /// /// Creates a new instance of the class. /// - /// A unique id for the collection being shaped. /// An identifier for the parent element. /// An identifier for the child element. /// A list of value comparers to compare identifiers. @@ -34,9 +33,7 @@ public class RelationalSplitCollectionShaperExpression : Expression, IPrintableE /// An expression used to create individual elements of the collection. /// A navigation associated with this collection, if any. /// The clr type of individual elements in the collection. - [Obsolete("Use ctor without collectionId")] public RelationalSplitCollectionShaperExpression( - int collectionId, Expression parentIdentifier, Expression childIdentifier, IReadOnlyList identifierValueComparers, @@ -51,7 +48,6 @@ public RelationalSplitCollectionShaperExpression( Check.NotNull(innerShaper, nameof(innerShaper)); Check.NotNull(elementType, nameof(elementType)); - CollectionId = collectionId; ParentIdentifier = parentIdentifier; ChildIdentifier = childIdentifier; IdentifierValueComparers = identifierValueComparers; @@ -61,46 +57,6 @@ public RelationalSplitCollectionShaperExpression( ElementType = elementType; } - /// - /// Creates a new instance of the class. - /// - /// An identifier for the parent element. - /// An identifier for the child element. - /// A list of value comparers to compare identifiers. - /// A SQL query to get values for this collection from database. - /// An expression used to create individual elements of the collection. - /// A navigation associated with this collection, if any. - /// The clr type of individual elements in the collection. - public RelationalSplitCollectionShaperExpression( - Expression parentIdentifier, - Expression childIdentifier, - IReadOnlyList identifierValueComparers, - SelectExpression selectExpression, - Expression innerShaper, - INavigationBase? navigation, - Type elementType) - { - Check.NotNull(parentIdentifier, nameof(parentIdentifier)); - Check.NotNull(childIdentifier, nameof(childIdentifier)); - Check.NotEmpty(identifierValueComparers, nameof(identifierValueComparers)); - Check.NotNull(innerShaper, nameof(innerShaper)); - Check.NotNull(elementType, nameof(elementType)); - - ParentIdentifier = parentIdentifier; - ChildIdentifier = childIdentifier; - IdentifierValueComparers = identifierValueComparers; - SelectExpression = selectExpression; - InnerShaper = innerShaper; - Navigation = navigation; - ElementType = elementType; - } - - /// - /// A unique id for this collection shaper. - /// - [Obsolete("CollectionId are not stored in shaper anymore. Shaper compiler assigns it as needed.")] - public virtual int CollectionId { get; } - /// /// The identifier for the parent element. /// diff --git a/src/EFCore.Relational/Query/SqlExpressionFactory.cs b/src/EFCore.Relational/Query/SqlExpressionFactory.cs index 8de8cdec8aa..3c718a6df21 100644 --- a/src/EFCore.Relational/Query/SqlExpressionFactory.cs +++ b/src/EFCore.Relational/Query/SqlExpressionFactory.cs @@ -510,16 +510,6 @@ public virtual SqlUnaryExpression Negate(SqlExpression operand) return MakeUnary(ExpressionType.Negate, operand, operand.Type, operand.TypeMapping)!; } - /// - [Obsolete("Use overload which takes IReadOnlyList instead of params")] - public virtual CaseExpression Case(SqlExpression operand, params CaseWhenClause[] whenClauses) - { - Check.NotNull(operand, nameof(operand)); - Check.NotNull(whenClauses, nameof(whenClauses)); - - return Case(operand, whenClauses, null); - } - /// public virtual CaseExpression Case(SqlExpression? operand, IReadOnlyList whenClauses, SqlExpression? elseResult) { @@ -574,73 +564,6 @@ public virtual CaseExpression Case(IReadOnlyList whenClauses, Sq return new CaseExpression(typeMappedWhenClauses, elseResult); } - /// - [Obsolete("Use overload that explicitly specifies value for 'argumentsPropagateNullability' argument.")] - public virtual SqlFunctionExpression Function( - string name, - IEnumerable arguments, - Type returnType, - RelationalTypeMapping? typeMapping = null) - => Function( - name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), returnType, typeMapping); - - /// - [Obsolete("Use overload that explicitly specifies value for 'argumentsPropagateNullability' argument.")] - public virtual SqlFunctionExpression Function( - string? schema, - string name, - IEnumerable arguments, - Type returnType, - RelationalTypeMapping? typeMapping = null) - => schema != null - ? Function( - schema, name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), returnType, - typeMapping) - : Function( - name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), returnType, typeMapping); - - /// - [Obsolete( - "Use overload that explicitly specifies values for 'instancePropagatesNullability' and 'argumentsPropagateNullability' arguments.")] - public virtual SqlFunctionExpression Function( - SqlExpression instance, - string name, - IEnumerable arguments, - Type returnType, - RelationalTypeMapping? typeMapping = null) - => Function( - instance, - name, - arguments, - nullable: true, - instancePropagatesNullability: false, - argumentsPropagateNullability: arguments.Select(a => false), - returnType, - typeMapping); - - /// - [Obsolete("Use NiladicFunction method.")] - public virtual SqlFunctionExpression Function(string name, Type returnType, RelationalTypeMapping? typeMapping = null) - => NiladicFunction(name, nullable: true, returnType, typeMapping); - - /// - [Obsolete("Use NiladicFunction method.")] - public virtual SqlFunctionExpression Function( - string schema, - string name, - Type returnType, - RelationalTypeMapping? typeMapping = null) - => NiladicFunction(schema, name, nullable: true, returnType, typeMapping); - - /// - [Obsolete("Use NiladicFunction method.")] - public virtual SqlFunctionExpression Function( - SqlExpression instance, - string name, - Type returnType, - RelationalTypeMapping? typeMapping = null) - => NiladicFunction(instance, name, nullable: true, instancePropagatesNullability: false, returnType, typeMapping); - /// public virtual SqlFunctionExpression Function( string name, @@ -848,21 +771,6 @@ public virtual SelectExpression Select(IEntityType entityType, TableExpressionBa return selectExpression; } - /// - [Obsolete("Use overload which takes TableExpressionBase by passing FromSqlExpression directly.")] - public virtual SelectExpression Select(IEntityType entityType, string sql, Expression sqlArguments) - { - Check.NotNull(entityType, nameof(entityType)); - Check.NotNull(sql, nameof(sql)); - - var tableExpression = new FromSqlExpression( - entityType.GetDefaultMappings().Single().Table.Name.Substring(0, 1).ToLowerInvariant(), sql, sqlArguments); - var selectExpression = new SelectExpression(entityType, tableExpression); - AddConditions(selectExpression, entityType); - - return selectExpression; - } - private void AddSelfConditions(SelectExpression selectExpression, IEntityType entityType, ITableBase? table = null) { // Add conditions if TPH @@ -1006,15 +914,5 @@ private EntityProjectionExpression GetMappedEntityProjectionExpression(SelectExp private SqlExpression IsNotNull(IProperty property, EntityProjectionExpression entityProjection) => IsNotNull(entityProjection.BindProperty(property)); - - /// - [Obsolete("Use IRelationalTypeMappingSource directly.")] - public virtual RelationalTypeMapping GetTypeMappingForValue(object? value) - => Dependencies.TypeMappingSource.GetMappingForValue(value, Dependencies.Model); - - /// - [Obsolete("Use IRelationalTypeMappingSource directly.")] - public virtual RelationalTypeMapping? FindMapping(Type type) - => Dependencies.TypeMappingSource.FindMapping(type, Dependencies.Model); } } diff --git a/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs index 297e186e411..08041a86a54 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs @@ -19,23 +19,6 @@ namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions /// public class FromSqlExpression : TableExpressionBase, IClonableTableExpressionBase { - /// - /// Creates a new instance of the class. - /// - /// A user-provided custom SQL for the table source. - /// A user-provided parameters to pass to the custom SQL. - /// A string alias for the table source. - [Obsolete("Use the constructor which takes alias as first argument.")] - public FromSqlExpression(string sql, Expression arguments, string alias) - : base(alias) - { - Check.NotEmpty(sql, nameof(sql)); - Check.NotNull(arguments, nameof(arguments)); - - Sql = sql; - Arguments = arguments; - } - /// /// Creates a new instance of the class. /// diff --git a/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs index a15a20e6866..3bab1c48d1c 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs @@ -21,40 +21,6 @@ namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions /// public class InExpression : SqlExpression { - /// - /// Creates a new instance of the class which represents a IN subquery expression. - /// - /// An item to look into values. - /// A value indicating if the item should be present in the values or absent. - /// A subquery in which item is searched. - /// The associated with the expression. - [Obsolete("Use overload which passes negated argument after subquery argument.")] - public InExpression( - SqlExpression item, - bool negated, - SelectExpression subquery, - RelationalTypeMapping? typeMapping) - : this(Check.NotNull(item, nameof(item)), null, Check.NotNull(subquery, nameof(subquery)), negated, typeMapping) - { - } - - /// - /// Creates a new instance of the class which represents a IN values expression. - /// - /// An item to look into values. - /// A value indicating if the item should be present in the values or absent. - /// A list of values in which item is searched. - /// The associated with the expression. - [Obsolete("Use overload which passes negated argument after values argument.")] - public InExpression( - SqlExpression item, - bool negated, - SqlExpression values, - RelationalTypeMapping? typeMapping) - : this(Check.NotNull(item, nameof(item)), Check.NotNull(values, nameof(values)), null, negated, typeMapping) - { - } - /// /// Creates a new instance of the class which represents a IN subquery expression. /// diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 040f879d34c..7da958e12cf 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -960,31 +960,6 @@ ConstantExpression AddEntityProjection(EntityProjectionExpression entityProjecti } } - /// - /// Clears all existing projections. - /// - [Obsolete("Use ReplaceProjection with empty list to clear out projections and associated bindings.")] - public void ClearProjection() - { - throw new InvalidOperationException("Clear Projection should clear the client/server projections"); - } - - /// - /// Replaces current projection mapping with a new one to change what is being projected out from this . - /// - /// A new projection mapping. - [Obsolete("Use ReplaceProjection method instead.")] - public void ReplaceProjectionMapping(IDictionary projectionMapping) - { - Check.NotNull(projectionMapping, nameof(projectionMapping)); - - _projectionMapping.Clear(); - foreach (var kvp in projectionMapping) - { - _projectionMapping[kvp.Key] = kvp.Value; - } - } - /// /// Replaces current projection mapping with a new one to change what is being projected out from this . /// @@ -1024,19 +999,6 @@ expression is SqlExpression } } - /// - /// Gets the projection mapped to the given . - /// - /// A projection member to search in the mapping. - /// The mapped projection for given projection member. - [Obsolete("Use GetProjection method using ProjectionBindingExpression to get mapped projection.")] - public Expression GetMappedProjection(ProjectionMember projectionMember) - { - Check.NotNull(projectionMember, nameof(projectionMember)); - - return _projectionMapping[projectionMember]; - } - /// /// Gets the projection mapped to the given . /// @@ -2657,127 +2619,6 @@ public Expression AddOuterApply( return AddJoin(JoinType.OuterApply, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression); } - #region ObsoleteMethods - - [Obsolete] - private void AddJoin( - JoinType joinType, - SelectExpression innerSelectExpression, - Type? transparentIdentifierType, - SqlExpression? joinPredicate) - { - AddJoin(joinType, ref innerSelectExpression, joinPredicate); - - if (transparentIdentifierType != null) - { - var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var projectionMapping = new Dictionary(); - foreach (var projection in _projectionMapping) - { - projectionMapping[projection.Key.Prepend(outerMemberInfo)] = projection.Value; - } - - var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); - var innerNullable = joinType == JoinType.LeftJoin || joinType == JoinType.OuterApply; - foreach (var projection in innerSelectExpression._projectionMapping) - { - var projectionToAdd = projection.Value; - if (innerNullable) - { - if (projectionToAdd is EntityProjectionExpression entityProjection) - { - projectionToAdd = entityProjection.MakeNullable(); - } - else if (projectionToAdd is ColumnExpression column) - { - projectionToAdd = column.MakeNullable(); - } - } - - projectionMapping[projection.Key.Prepend(innerMemberInfo)] = projectionToAdd; - } - - _projectionMapping = projectionMapping; - } - } - - /// - /// Adds the given to table sources using INNER JOIN. - /// - /// A to join with. - /// A predicate to use for the join. - /// The type of the result generated after performing the join. - [Obsolete("Use the other overloads.")] - public void AddInnerJoin( - SelectExpression innerSelectExpression, - SqlExpression joinPredicate, - Type? transparentIdentifierType) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - Check.NotNull(joinPredicate, nameof(joinPredicate)); - - AddJoin(JoinType.InnerJoin, innerSelectExpression, transparentIdentifierType, joinPredicate); - } - - /// - /// Adds the given to table sources using LEFT JOIN. - /// - /// A to join with. - /// A predicate to use for the join. - /// The type of the result generated after performing the join. - [Obsolete("Use the other overloads.")] - public void AddLeftJoin( - SelectExpression innerSelectExpression, - SqlExpression joinPredicate, - Type? transparentIdentifierType) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - Check.NotNull(joinPredicate, nameof(joinPredicate)); - - AddJoin(JoinType.LeftJoin, innerSelectExpression, transparentIdentifierType, joinPredicate); - } - - /// - /// Adds the given to table sources using CROSS JOIN. - /// - /// A to join with. - /// The type of the result generated after performing the join. - [Obsolete("Use the other overloads.")] - public void AddCrossJoin(SelectExpression innerSelectExpression, Type? transparentIdentifierType) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - - AddJoin(JoinType.CrossJoin, innerSelectExpression, transparentIdentifierType, null); - } - - /// - /// Adds the given to table sources using CROSS APPLY. - /// - /// A to join with. - /// The type of the result generated after performing the join. - [Obsolete("Use the other overloads.")] - public void AddCrossApply(SelectExpression innerSelectExpression, Type? transparentIdentifierType) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - - AddJoin(JoinType.CrossApply, innerSelectExpression, transparentIdentifierType, null); - } - - /// - /// Adds the given to table sources using OUTER APPLY. - /// - /// A to join with. - /// The type of the result generated after performing the join. - [Obsolete("Use the other overloads.")] - public void AddOuterApply(SelectExpression innerSelectExpression, Type? transparentIdentifierType) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - - AddJoin(JoinType.OuterApply, innerSelectExpression, transparentIdentifierType, null); - } - - #endregion - /// /// Pushes down the into a subquery. /// @@ -3517,11 +3358,8 @@ List VisitList(List list, bool inPlace, out bool changed) /// The property of the result. /// The property of the result. /// The property of the result. - /// The property of the result. - /// The property of the result. /// This expression if no children changed, or an expression with the updated children. // This does not take internal states since when using this method SelectExpression should be finalized - [Obsolete("Use the overload which does not require distinct & alias parameter.")] public SelectExpression Update( IReadOnlyList projections, IReadOnlyList tables, @@ -3530,9 +3368,7 @@ public SelectExpression Update( SqlExpression? having, IReadOnlyList orderings, SqlExpression? limit, - SqlExpression? offset, - bool distinct, - string? alias) + SqlExpression? offset) { Check.NotNull(projections, nameof(projections)); Check.NotNull(tables, nameof(tables)); @@ -3547,14 +3383,14 @@ public SelectExpression Update( var newTableReferences = _tableReferences.ToList(); var newSelectExpression = new SelectExpression( - alias, projections.ToList(), tables.ToList(), newTableReferences, groupBy.ToList(), orderings.ToList()) + Alias, projections.ToList(), tables.ToList(), newTableReferences, groupBy.ToList(), orderings.ToList()) { _projectionMapping = projectionMapping, Predicate = predicate, Having = having, Offset = offset, Limit = limit, - IsDistinct = distinct, + IsDistinct = IsDistinct, Tags = Tags }; @@ -3573,40 +3409,6 @@ public SelectExpression Update( return newSelectExpression; } - /// - /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will - /// return this expression. - /// - /// The property of the result. - /// The property of the result. - /// The property of the result. - /// The property of the result. - /// The property of the result. - /// The property of the result. - /// The property of the result. - /// The property of the result. - /// This expression if no children changed, or an expression with the updated children. - // This does not take internal states since when using this method SelectExpression should be finalized - public SelectExpression Update( - IReadOnlyList projections, - IReadOnlyList tables, - SqlExpression? predicate, - IReadOnlyList groupBy, - SqlExpression? having, - IReadOnlyList orderings, - SqlExpression? limit, - SqlExpression? offset) - { - Check.NotNull(projections, nameof(projections)); - Check.NotNull(tables, nameof(tables)); - Check.NotNull(groupBy, nameof(groupBy)); - Check.NotNull(orderings, nameof(orderings)); - -#pragma warning disable CS0618 // Type or member is obsolete - return Update(projections, tables, predicate, groupBy, having, orderings, limit, offset, IsDistinct, Alias); -#pragma warning restore CS0618 // Type or member is obsolete - } - /// protected override void Print(ExpressionPrinter expressionPrinter) { diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs index a4227bd96e0..7ce00a2ae94 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs @@ -410,115 +410,5 @@ public override int GetHashCode() return hash.ToHashCode(); } - - #region ObsoleteMethods - - /// - /// Creates a new instance of the class. - /// - /// The name of the function. - /// The of the expression. - /// The associated with the expression. - [Obsolete("Use new SqlFunctionExpression(...) with appropriate arguments.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static SqlFunctionExpression CreateNiladic( - string name, - Type type, - RelationalTypeMapping? typeMapping) - => new(name, nullable: true, type, typeMapping); - - /// - /// Creates a new instance of the class. - /// - /// The schema in which the function is defined. - /// The name of the function. - /// The of the expression. - /// The associated with the expression. - [Obsolete("Use new SqlFunctionExpression(...) with appropriate arguments.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static SqlFunctionExpression CreateNiladic( - string schema, - string name, - Type type, - RelationalTypeMapping? typeMapping) - => new(schema, name, nullable: true, type, typeMapping); - - /// - /// Creates a new instance of the class. - /// - /// An expression on which the function is defined. - /// The name of the function. - /// The of the expression. - /// The associated with the expression. - [Obsolete("Use new SqlFunctionExpression(...) with appropriate arguments.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static SqlFunctionExpression CreateNiladic( - SqlExpression instance, - string name, - Type type, - RelationalTypeMapping? typeMapping) - => new(instance, name, nullable: true, instancePropagatesNullability: false, type, typeMapping); - - /// - /// Creates a new instance of the class. - /// - /// An expression on which the function is applied. - /// The name of the function. - /// The arguments of the function. - /// The of the expression. - /// The associated with the expression. - [Obsolete("Use new SqlFunctionExpression(...) with appropriate arguments.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static SqlFunctionExpression Create( - SqlExpression instance, - string name, - IEnumerable arguments, - Type type, - RelationalTypeMapping? typeMapping) - => new( - instance, - name, - arguments, - nullable: true, - instancePropagatesNullability: false, - argumentsPropagateNullability: arguments.Select(a => false), - type, - typeMapping); - - /// - /// Creates a new instance of the class. - /// - /// The name of the function. - /// The arguments of the function. - /// The of the expression. - /// The associated with the expression. - [Obsolete("Use new SqlFunctionExpression(...) with appropriate arguments.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static SqlFunctionExpression Create( - string name, - IEnumerable arguments, - Type type, - RelationalTypeMapping? typeMapping) - => new(name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), type, typeMapping); - - /// - /// Creates a new instance of the class. - /// - /// The schema in which the function is defined. - /// The name of the function. - /// The arguments of the function. - /// The of the expression. - /// The associated with the expression. - [Obsolete("Use new SqlFunctionExpression(...) with appropriate arguments.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static SqlFunctionExpression Create( - string? schema, - string name, - IEnumerable arguments, - Type type, - RelationalTypeMapping? typeMapping) - => new(schema, name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), type, typeMapping); - - #endregion } } diff --git a/src/EFCore.Relational/Storage/ReaderColumn.cs b/src/EFCore.Relational/Storage/ReaderColumn.cs index 5036d3995ef..d6799944269 100644 --- a/src/EFCore.Relational/Storage/ReaderColumn.cs +++ b/src/EFCore.Relational/Storage/ReaderColumn.cs @@ -26,18 +26,6 @@ public abstract class ReaderColumn { private static readonly ConcurrentDictionary _constructors = new(); - /// - /// Creates a new instance of the class. - /// - /// The CLR type of the column. - /// A value indicating if the column is nullable. - /// The name of the column. - [Obsolete("Use constructor which also takes IPropertyBase.")] - protected ReaderColumn(Type type, bool nullable, string? name) - : this(type, nullable, name, null) - { - } - /// /// Creates a new instance of the class. /// @@ -73,20 +61,6 @@ protected ReaderColumn(Type type, bool nullable, string? name, IPropertyBase? pr /// public virtual IPropertyBase? Property { get; } - /// - /// Creates an instance of . - /// - /// The type of the column. - /// Whether the column can contain values. - /// The column name if it is used to access the column values, otherwise. - /// - /// A used to get the field value for this column. - /// - /// An instance of . - [Obsolete("Use method which also takes IPropertyBase.")] - public static ReaderColumn Create(Type type, bool nullable, string? columnName, object readFunc) - => (ReaderColumn)GetConstructor(type).Invoke(new[] { nullable, columnName, readFunc }); - /// /// Creates an instance of . /// diff --git a/src/EFCore.Relational/Storage/ReaderColumn`.cs b/src/EFCore.Relational/Storage/ReaderColumn`.cs index 5ed21342990..b1e82765b36 100644 --- a/src/EFCore.Relational/Storage/ReaderColumn`.cs +++ b/src/EFCore.Relational/Storage/ReaderColumn`.cs @@ -22,18 +22,6 @@ namespace Microsoft.EntityFrameworkCore.Storage /// public class ReaderColumn : ReaderColumn { - /// - /// Creates a new instance of the class. - /// - /// A value indicating if the column is nullable. - /// The name of the column. - /// A function to get field value for the column from the reader. - [Obsolete("Use constructor which also takes IPropertyBase.")] - public ReaderColumn(bool nullable, string? name, Func getFieldValue) - : this(nullable, name, property: null, getFieldValue) - { - } - /// /// Creates a new instance of the class. /// diff --git a/src/EFCore/Query/CollectionShaperExpression.cs b/src/EFCore/Query/CollectionShaperExpression.cs deleted file mode 100644 index 965f0a7b299..00000000000 --- a/src/EFCore/Query/CollectionShaperExpression.cs +++ /dev/null @@ -1,124 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; - -namespace Microsoft.EntityFrameworkCore.Query -{ - /// - /// - /// An expression that represents creation of a collection in . - /// - /// - /// This type is typically used by database providers (and other extensions). It is generally - /// not used in application code. - /// - /// - /// - /// See Implementation of database providers and extensions - /// and How EF Core queries work for more information. - /// - [Obsolete("Use provider specific expressions for collection results.")] - public class CollectionShaperExpression : Expression, IPrintableExpression - { - /// - /// Creates a new instance of the class. - /// - /// An expression reprensenting how to get value from query to create the collection. - /// An expression used to create individual elements of the collection. - /// A navigation associated with this collection, if any. - /// The clr type of individual elements in the collection. - public CollectionShaperExpression( - Expression projection, - Expression innerShaper, - INavigationBase? navigation, - Type elementType) - { - Check.NotNull(projection, nameof(projection)); - Check.NotNull(innerShaper, nameof(innerShaper)); - - Projection = projection; - InnerShaper = innerShaper; - Navigation = navigation; - ElementType = elementType; - } - - /// - /// The expression to get value from query for this collection. - /// - public virtual Expression Projection { get; } - - /// - /// The expression to create inner elements. - /// - public virtual Expression InnerShaper { get; } - - /// - /// The navigation if associated with the collection. - /// - public virtual INavigationBase? Navigation { get; } - - /// - /// The clr type of elements of the collection. - /// - public virtual Type ElementType { get; } - - /// - public sealed override ExpressionType NodeType - => ExpressionType.Extension; - - /// - public override Type Type - => Navigation?.ClrType ?? typeof(List<>).MakeGenericType(ElementType); - - /// - protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - var projection = visitor.Visit(Projection); - var innerShaper = visitor.Visit(InnerShaper); - - return Update(projection, innerShaper); - } - - /// - /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will - /// return this expression. - /// - /// The property of the result. - /// The property of the result. - /// This expression if no children changed, or an expression with the updated children. - public virtual CollectionShaperExpression Update( - Expression projection, - Expression innerShaper) - { - Check.NotNull(projection, nameof(projection)); - Check.NotNull(innerShaper, nameof(innerShaper)); - - return projection != Projection || innerShaper != InnerShaper - ? new CollectionShaperExpression(projection, innerShaper, Navigation, ElementType) - : this; - } - - /// - void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) - { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - - expressionPrinter.AppendLine("CollectionShaper:"); - using (expressionPrinter.Indent()) - { - expressionPrinter.Append("("); - expressionPrinter.Visit(Projection); - expressionPrinter.Append(", "); - expressionPrinter.Visit(InnerShaper); - expressionPrinter.AppendLine($", {Navigation?.Name})"); - } - } - } -} diff --git a/src/EFCore/Query/EntityShaperExpression.cs b/src/EFCore/Query/EntityShaperExpression.cs index 3e3a9a4e03b..879a1862561 100644 --- a/src/EFCore/Query/EntityShaperExpression.cs +++ b/src/EFCore/Query/EntityShaperExpression.cs @@ -229,14 +229,6 @@ public virtual EntityShaperExpression WithEntityType(IEntityType entityType) : this; } - /// - /// Marks this shaper as nullable, indicating that it can shape null entity instances. - /// - /// This expression if nullability not changed, or an expression with updated nullability. - [Obsolete("Use MakeNullable() instead.")] - public virtual EntityShaperExpression MarkAsNullable() - => MakeNullable(); - /// /// Assigns nullability for this shaper, indicating whether it can shape null entity instances or not. /// diff --git a/src/EFCore/Query/MaterializeCollectionNavigationExpression.cs b/src/EFCore/Query/MaterializeCollectionNavigationExpression.cs index 66737341baa..9035fab4ccf 100644 --- a/src/EFCore/Query/MaterializeCollectionNavigationExpression.cs +++ b/src/EFCore/Query/MaterializeCollectionNavigationExpression.cs @@ -24,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.Query public class MaterializeCollectionNavigationExpression : Expression, IPrintableExpression { /// - /// Creates a new instance of the class. + /// Creates a new instance of the class. /// /// An expression reprensenting how to get value from query to create the collection. /// A navigation associated with this collection. diff --git a/src/EFCore/Query/ProjectionBindingExpression.cs b/src/EFCore/Query/ProjectionBindingExpression.cs index b6288f83b0c..c62e790f770 100644 --- a/src/EFCore/Query/ProjectionBindingExpression.cs +++ b/src/EFCore/Query/ProjectionBindingExpression.cs @@ -65,24 +65,6 @@ public ProjectionBindingExpression( Type = type; } - /// - /// Creates a new instance of the class. - /// - /// The query expression to get the value from. - /// The index map to bind with query expression projection for ValueBuffer. - [Obsolete("The dictionary should be stored in client projection in query expression and access via index based binding.")] - public ProjectionBindingExpression( - Expression queryExpression, - IReadOnlyDictionary indexMap) - { - Check.NotNull(queryExpression, nameof(queryExpression)); - Check.NotNull(indexMap, nameof(indexMap)); - - QueryExpression = queryExpression; - IndexMap = indexMap; - Type = typeof(ValueBuffer); - } - /// /// The query expression to bind with. /// @@ -98,12 +80,6 @@ public ProjectionBindingExpression( /// public virtual int? Index { get; } - /// - /// The projection member to bind if binding is via index map for a value buffer. - /// - [Obsolete("The dictionary should be stored in client projection in query expression and access via index based binding.")] - public virtual IReadOnlyDictionary? IndexMap { get; } - /// public override Type Type { get; } @@ -133,18 +109,6 @@ void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { expressionPrinter.Append(Index.ToString()!); } -#pragma warning disable CS0618 // Type or member is obsolete - else if (IndexMap != null) - { - using (expressionPrinter.Indent()) - { - foreach (var kvp in IndexMap) - { - expressionPrinter.AppendLine($"{kvp.Key.Name}:{kvp.Value},"); - } - } - } -#pragma warning restore CS0618 // Type or member is obsolete } /// @@ -159,16 +123,10 @@ private bool Equals(ProjectionBindingExpression projectionBindingExpression) && Type == projectionBindingExpression.Type && (ProjectionMember?.Equals(projectionBindingExpression.ProjectionMember) ?? projectionBindingExpression.ProjectionMember == null) - && Index == projectionBindingExpression.Index - // Using reference equality here since if we are this far, we don't need to compare this. -#pragma warning disable CS0618 // Type or member is obsolete - && IndexMap == projectionBindingExpression.IndexMap; -#pragma warning restore CS0618 // Type or member is obsolete + && Index == projectionBindingExpression.Index; /// public override int GetHashCode() -#pragma warning disable CS0618 // Type or member is obsolete - => HashCode.Combine(QueryExpression, ProjectionMember, Index, IndexMap); -#pragma warning restore CS0618 // Type or member is obsolete + => HashCode.Combine(QueryExpression, ProjectionMember, Index); } } diff --git a/src/EFCore/Query/QueryCompilationContext.cs b/src/EFCore/Query/QueryCompilationContext.cs index 7cbb23f8a6f..a3aa10e9fce 100644 --- a/src/EFCore/Query/QueryCompilationContext.cs +++ b/src/EFCore/Query/QueryCompilationContext.cs @@ -124,13 +124,6 @@ public QueryCompilationContext( /// public virtual QueryTrackingBehavior QueryTrackingBehavior { get; internal set; } - /// - /// A value indicating whether it is tracking query. - /// - [Obsolete("Use " + nameof(QueryTrackingBehavior) + " instead.")] - public virtual bool IsTracking - => QueryTrackingBehavior == QueryTrackingBehavior.TrackAll; - /// /// A value indicating whether the underlying server query needs to pre-buffer all data. /// diff --git a/src/EFCore/Query/QueryContext.cs b/src/EFCore/Query/QueryContext.cs index b3183a674d0..6c01b70f3a7 100644 --- a/src/EFCore/Query/QueryContext.cs +++ b/src/EFCore/Query/QueryContext.cs @@ -76,26 +76,12 @@ public virtual void SetNavigationIsLoaded(object entity, INavigationBase navigat _stateManager!.TryGetEntry(entity)!.SetIsLoaded(navigation); } - /// - /// The query provider. - /// - [Obsolete("The service requiring IQueryProvider should inject it directly.")] - public virtual IQueryProvider QueryProvider - => Dependencies.QueryProvider; - /// /// The execution strategy to use while executing the query. /// public virtual IExecutionStrategy ExecutionStrategy => Dependencies.ExecutionStrategy; - /// - /// The execution strategy factory to use while executing the query. - /// - [Obsolete("Use ExecutionStrategy instead")] - public virtual IExecutionStrategyFactory ExecutionStrategyFactory - => Dependencies.ExecutionStrategyFactory; - /// /// The concurrency detector to use while executing the query. /// diff --git a/src/EFCore/Query/QueryContextDependencies.cs b/src/EFCore/Query/QueryContextDependencies.cs index ce115e66e36..31281c21103 100644 --- a/src/EFCore/Query/QueryContextDependencies.cs +++ b/src/EFCore/Query/QueryContextDependencies.cs @@ -57,16 +57,12 @@ public sealed record QueryContextDependencies public QueryContextDependencies( ICurrentDbContext currentContext, IExecutionStrategy executionStrategy, - IExecutionStrategyFactory executionStrategyFactory, IConcurrencyDetector concurrencyDetector, IDiagnosticsLogger commandLogger, IDiagnosticsLogger queryLogger) { CurrentContext = currentContext; ExecutionStrategy = executionStrategy; -#pragma warning disable CS0618 // Type or member is obsolete - ExecutionStrategyFactory = executionStrategyFactory; -#pragma warning restore CS0618 // Type or member is obsolete ConcurrencyDetector = concurrencyDetector; CommandLogger = commandLogger; QueryLogger = queryLogger; @@ -87,24 +83,11 @@ public QueryContextDependencies( public IStateManager StateManager => CurrentContext.GetDependencies().StateManager; - /// - /// Gets the query provider. - /// - [Obsolete("Use the service by getting it from " + nameof(CurrentContext) + ".")] - public IQueryProvider QueryProvider - => CurrentContext.GetDependencies().QueryProvider; - /// /// The execution strategy. /// public IExecutionStrategy ExecutionStrategy { get; init; } - /// - /// The execution strategy factory. - /// - [Obsolete("Use ExecutionStrategy instead")] - public IExecutionStrategyFactory ExecutionStrategyFactory { get; init; } - /// /// Gets the concurrency detector. /// diff --git a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs index d05e1da3da4..553d75c3ec9 100644 --- a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs @@ -525,110 +525,6 @@ protected virtual Expression MarkShaperNullable(Expression shaperExpression) return _entityShaperNullableMarkingExpressionVisitor.Visit(shaperExpression); } - /// - /// Translates the result selector for join operation. - /// - /// - /// The shaped query expression for outer source. The join on the query expression is already performed on outer query - /// expression. - /// - /// The result selector lambda to translate. - /// The shaper for inner source. - /// The clr type of transparent identifier created from result. - /// The shaped query expression after translation of result selector. - [Obsolete("QueryExpressions should combine shapers to work in client eval scenarios.")] - protected virtual ShapedQueryExpression TranslateResultSelectorForJoin( - ShapedQueryExpression outer, - LambdaExpression resultSelector, - Expression innerShaper, - Type transparentIdentifierType) - { - Check.NotNull(outer, nameof(outer)); - Check.NotNull(resultSelector, nameof(resultSelector)); - Check.NotNull(innerShaper, nameof(innerShaper)); - Check.NotNull(transparentIdentifierType, nameof(transparentIdentifierType)); - - outer = outer.UpdateShaperExpression( - CombineShapers(outer.QueryExpression, outer.ShaperExpression, innerShaper, transparentIdentifierType)); - - var transparentIdentifierParameter = Expression.Parameter(transparentIdentifierType); - - Expression original1 = resultSelector.Parameters[0]; - var replacement1 = AccessOuterTransparentField(transparentIdentifierType, transparentIdentifierParameter); - Expression original2 = resultSelector.Parameters[1]; - var replacement2 = AccessInnerTransparentField(transparentIdentifierType, transparentIdentifierParameter); - var newResultSelector = Expression.Lambda( - new ReplacingExpressionVisitor( - new[] { original1, original2 }, new[] { replacement1, replacement2 }) - .Visit(resultSelector.Body), - transparentIdentifierParameter); - - return TranslateSelect(outer, newResultSelector); - } - - [Obsolete] - private Expression CombineShapers( - Expression queryExpression, - Expression outerShaper, - Expression innerShaper, - Type transparentIdentifierType) - { - var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); - outerShaper = new MemberAccessShiftingExpressionVisitor(queryExpression, outerMemberInfo).Visit(outerShaper); - innerShaper = new MemberAccessShiftingExpressionVisitor(queryExpression, innerMemberInfo).Visit(innerShaper); - - return Expression.New( - transparentIdentifierType.GetTypeInfo().DeclaredConstructors.Single(), - new[] { outerShaper, innerShaper }, outerMemberInfo, innerMemberInfo); - } - - [Obsolete] - private sealed class MemberAccessShiftingExpressionVisitor : ExpressionVisitor - { - private readonly Expression _queryExpression; - private readonly MemberInfo _memberShift; - - public MemberAccessShiftingExpressionVisitor(Expression queryExpression, MemberInfo memberShift) - { - _queryExpression = queryExpression; - _memberShift = memberShift; - } - - protected override Expression VisitExtension(Expression extensionExpression) - { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - - return extensionExpression is ProjectionBindingExpression projectionBindingExpression - ? new ProjectionBindingExpression( - _queryExpression, - // ProjectionMember would be non-null here as we are shifting members - projectionBindingExpression.ProjectionMember!.Prepend(_memberShift), - projectionBindingExpression.Type) - : base.VisitExtension(extensionExpression); - } - } - - [Obsolete] - private static Expression AccessOuterTransparentField( - Type transparentIdentifierType, - Expression targetExpression) - { - var fieldInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - - return Expression.Field(targetExpression, fieldInfo); - } - - [Obsolete] - private static Expression AccessInnerTransparentField( - Type transparentIdentifierType, - Expression targetExpression) - { - var fieldInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); - - return Expression.Field(targetExpression, fieldInfo); - } - /// /// Translates the given subquery. /// @@ -654,14 +550,6 @@ private static Expression AccessInnerTransparentField( /// A visitor to translate subquery. protected abstract QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor(); - /// - /// Creates a for the given type by finding its entity type in the model. - /// - /// The clr type of the entity type to look for. - /// A shaped query expression for the given clr type. - [Obsolete("Use overload which takes IEntityType.")] - protected abstract ShapedQueryExpression CreateShapedQueryExpression(Type elementType); - /// /// Creates a for the given entity type. /// diff --git a/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs b/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs index dfd9b6286f6..cb722070a63 100644 --- a/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs +++ b/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs @@ -946,9 +946,6 @@ protected ApiConsistencyFixtureBase() typeof(QueryCompilationContextDependencies).GetProperty( nameof(QueryCompilationContextDependencies.QueryTrackingBehavior)), typeof(QueryContextDependencies).GetProperty(nameof(QueryContextDependencies.StateManager)), -#pragma warning disable CS0618 // Type or member is obsolete - typeof(QueryContextDependencies).GetProperty(nameof(QueryContextDependencies.QueryProvider)) -#pragma warning restore CS0618 // Type or member is obsolete }; public Dictionary MetadataTypes { get; }