Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private SqlParameterExpression VisitSqlParameter(SqlParameterExpression paramete
uniquifiedName,
parameter.Type,
parameter.IsNullable,
parameter.ShouldBeConstantized,
parameter.ParameterExpressionMode,
parameter.TypeMapping);

return _sqlParameters[newParameter.InvariantName] = newParameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& methodCallExpression.Arguments[0] is ParameterQueryRootExpression parameterSource
&& TranslateExpression(methodCallExpression.Arguments[1]) is SqlExpression item
&& _sqlTranslator.Visit(parameterSource.QueryParameterExpression) is SqlParameterExpression sqlParameterExpression
&& !parameterSource.QueryParameterExpression.ShouldNotBeConstantized)
&& (parameterSource.QueryParameterExpression.ParameterExpressionMode is not ParameterExpressionMode.Parameter
&& parameterSource.QueryParameterExpression.ParameterExpressionMode is not ParameterExpressionMode.MultipleParameters))
{
var inExpression = _sqlExpressionFactory.In(item, sqlParameterExpression);
var selectExpression = new SelectExpression(inExpression, _sqlAliasManager);
Expand Down Expand Up @@ -298,11 +299,12 @@ JsonScalarExpression jsonScalar

var tableAlias = _sqlAliasManager.GenerateTableAlias(sqlParameterExpression.Name.TrimStart('_'));

var constants = queryParameter.ShouldBeConstantized
var constants = queryParameter.ParameterExpressionMode is ParameterExpressionMode.Constants
|| (_parameterizedCollectionMode is ParameterizedCollectionMode.Constants
&& !queryParameter.ShouldNotBeConstantized);
var multipleParameters = _parameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& !queryParameter.ShouldNotBeConstantized;
&& queryParameter.ParameterExpressionMode is null);
var multipleParameters = queryParameter.ParameterExpressionMode is ParameterExpressionMode.MultipleParameters
|| (_parameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& queryParameter.ParameterExpressionMode is null);
if (constants || multipleParameters)
{
var valuesExpression = new ValuesExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
name: queryParameter.Name,
queryParameter.Type,
nullable: false,
queryParameter.ShouldBeConstantized,
queryParameter.ParameterExpressionMode,
typeMapping: null);
}

Expand All @@ -525,7 +525,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
name: queryParameter.Name,
queryParameter.Type,
queryParameter.Type.IsNullableType(),
queryParameter.ShouldBeConstantized,
queryParameter.ParameterExpressionMode,
typeMapping: null);

case StructuralTypeShaperExpression shaper:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class SqlParameterExpression : SqlExpression
/// <param name="type">The <see cref="Type" /> of the expression.</param>
/// <param name="typeMapping">The <see cref="RelationalTypeMapping" /> associated with the expression.</param>
public SqlParameterExpression(string name, Type type, RelationalTypeMapping? typeMapping)
: this(invariantName: name, name: name, type.UnwrapNullableType(), type.IsNullableType(), shouldBeConstantized: false, typeMapping)
: this(invariantName: name, name: name, type.UnwrapNullableType(), type.IsNullableType(), parameterExpressionMode: null, typeMapping)
{
}

Expand All @@ -31,21 +31,21 @@ public SqlParameterExpression(string name, Type type, RelationalTypeMapping? typ
/// </param>
/// <param name="type">The <see cref="Type" /> of the expression.</param>
/// <param name="nullable">Whether this parameter can have null values.</param>
/// <param name="shouldBeConstantized">Whether the user has indicated that this query parameter should be inlined as a constant.</param>
/// <param name="parameterExpressionMode">How the parameter should be handled.</param>
/// <param name="typeMapping">The <see cref="RelationalTypeMapping" /> associated with the expression.</param>
public SqlParameterExpression(
string invariantName,
string name,
Type type,
bool nullable,
bool shouldBeConstantized,
ParameterExpressionMode? parameterExpressionMode,
RelationalTypeMapping? typeMapping)
: base(type.UnwrapNullableType(), typeMapping)
{
InvariantName = invariantName;
Name = name;
IsNullable = nullable;
ShouldBeConstantized = shouldBeConstantized;
ParameterExpressionMode = parameterExpressionMode;
}

/// <summary>
Expand All @@ -65,17 +65,17 @@ public SqlParameterExpression(
public bool IsNullable { get; }

/// <summary>
/// Whether the user has indicated that this query parameter should be inlined as a constant.
/// How the parameter should be handled.
/// </summary>
public bool ShouldBeConstantized { get; }
public ParameterExpressionMode? ParameterExpressionMode { get; }

/// <summary>
/// Applies supplied type mapping to this expression.
/// </summary>
/// <param name="typeMapping">A relational type mapping to apply.</param>
/// <returns>A new expression which has supplied type mapping.</returns>
public SqlExpression ApplyTypeMapping(RelationalTypeMapping? typeMapping)
=> new SqlParameterExpression(InvariantName, Name, Type, IsNullable, ShouldBeConstantized, typeMapping);
=> new SqlParameterExpression(InvariantName, Name, Type, IsNullable, ParameterExpressionMode, typeMapping);

/// <inheritdoc />
protected override Expression VisitChildren(ExpressionVisitor visitor)
Expand Down
38 changes: 16 additions & 22 deletions src/EFCore.Relational/Query/SqlNullabilityProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ protected override Expression VisitExtension(Expression node)

var processedValues = new List<RowValueExpression>();

switch (ParameterizedCollectionMode)
switch (ParameterizedCollectionMode, valuesParameter.ParameterExpressionMode)
{
case ParameterizedCollectionMode.MultipleParameters
when !valuesParameter.ShouldBeConstantized:
case (ParameterizedCollectionMode.MultipleParameters, null):
case (_, ParameterExpressionMode.MultipleParameters):
{
var expandedParameters = _collectionParameterExpansionMap.GetOrAddNew(valuesParameter);
for (var i = 0; i < values.Count; i++)
Expand All @@ -156,11 +156,8 @@ protected override Expression VisitExtension(Expression node)
break;
}

case ParameterizedCollectionMode.Constants:
case ParameterizedCollectionMode.Parameter
when valuesParameter.ShouldBeConstantized:
case ParameterizedCollectionMode.MultipleParameters
when valuesParameter.ShouldBeConstantized:
case (ParameterizedCollectionMode.Constants, null):
case (_, ParameterExpressionMode.Constants):
{
foreach (var value in values)
{
Expand Down Expand Up @@ -820,18 +817,15 @@ InExpression ProcessInExpressionValues(

processedValues = [];

var useParameters = ParameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& !valuesParameter.ShouldBeConstantized;
var useConstants =
ParameterizedCollectionMode is ParameterizedCollectionMode.Constants
||
(ParameterizedCollectionMode is ParameterizedCollectionMode.Parameter
&& valuesParameter.ShouldBeConstantized)
||
(ParameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& valuesParameter.ShouldBeConstantized);
var useParameter = ParameterizedCollectionMode is ParameterizedCollectionMode.Parameter
&& !valuesParameter.ShouldBeConstantized;
var useMultipleParameters = valuesParameter.ParameterExpressionMode is ParameterExpressionMode.MultipleParameters
|| (ParameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& valuesParameter.ParameterExpressionMode is null);
var useConstants = valuesParameter.ParameterExpressionMode is ParameterExpressionMode.Constants
|| (ParameterizedCollectionMode is ParameterizedCollectionMode.Constants
&& valuesParameter.ParameterExpressionMode is null);
var useParameter = valuesParameter.ParameterExpressionMode is ParameterExpressionMode.Parameter
|| (ParameterizedCollectionMode is ParameterizedCollectionMode.Parameter
&& valuesParameter.ParameterExpressionMode is null);
var expandedParameters = _collectionParameterExpansionMap.GetOrAddNew(valuesParameter);
var expandedParametersCounter = 0;
for (var i = 0; i < values.Count; i++)
Expand All @@ -842,7 +836,7 @@ ParameterizedCollectionMode is ParameterizedCollectionMode.Constants
continue;
}

switch (useParameters, useConstants, useParameter)
switch (useMultipleParameters, useConstants, useParameter)
{
case (true, false, false):
// see #36311 for more info
Expand Down Expand Up @@ -1426,7 +1420,7 @@ protected virtual SqlExpression VisitSqlParameter(

nullable = false;

if (sqlParameterExpression.ShouldBeConstantized)
if (sqlParameterExpression.ParameterExpressionMode is ParameterExpressionMode.Constants)
{
var parameters = ParametersFacade.GetParametersAndDisableSqlCaching();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ protected override Expression VisitExtension(Expression node)
switch (node)
{
case ValuesExpression { ValuesParameter: SqlParameterExpression valuesParameter } valuesExpression
when ParameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& !valuesParameter.ShouldBeConstantized:
when valuesParameter.ParameterExpressionMode is ParameterExpressionMode.MultipleParameters
|| (ParameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& valuesParameter.ParameterExpressionMode is null):
{
Check.DebugAssert(valuesParameter.TypeMapping is not null);
Check.DebugAssert(valuesParameter.TypeMapping.ElementTypeMapping is not null);
Expand Down Expand Up @@ -237,8 +238,9 @@ protected override SqlExpression VisitIn(InExpression inExpression, bool allowOp
switch (inExpression.ValuesParameter)
{
case SqlParameterExpression valuesParameter
when ParameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& !valuesParameter.ShouldBeConstantized:
when valuesParameter.ParameterExpressionMode is ParameterExpressionMode.MultipleParameters
|| (ParameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& valuesParameter.ParameterExpressionMode is null):
{
Check.DebugAssert(valuesParameter.TypeMapping is not null);
Check.DebugAssert(valuesParameter.TypeMapping.ElementTypeMapping is not null);
Expand Down
30 changes: 13 additions & 17 deletions src/EFCore/Properties/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@
<data name="CanOnlyConfigureExistingNavigations" xml:space="preserve">
<value>Navigation '{1_entityType}.{0_navigationName}' was not found. Please add the navigation to the entity type before configuring it.</value>
</data>
<data name="ChangeTrackingInterfaceMissing" xml:space="preserve">
<value>The entity type '{entityType}' is configured to use the '{changeTrackingStrategy}' change tracking strategy, but does not implement the required '{notificationInterface}' interface. Implement '{notificationInterface}' on '{entityType}' or use a different change tracking strategy.</value>
</data>
<data name="CircularDependency" xml:space="preserve">
<value>Unable to save changes because a circular dependency was detected in the data to be saved: '{cycle}'.</value>
</data>
Expand Down Expand Up @@ -495,15 +492,12 @@
<data name="EFConstantNotSupportedInPrecompiledQueries" xml:space="preserve">
<value>The EF.Constant&lt;T&gt; method is not supported when using precompiled queries.</value>
</data>
<data name="EFConstantWithNonEvaluatableArgument" xml:space="preserve">
<value>The EF.Constant&lt;T&gt; method may only be used with an argument that can be evaluated client-side and does not contain any reference to database-side entities.</value>
<data name="EFMethodWithNonEvaluatableArgument" xml:space="preserve">
<value>The {methodName} method may only be used with an argument that can be evaluated client-side and does not contain any reference to database-side entities.</value>
</data>
<data name="EFParameterInvoked" xml:space="preserve">
<value>The EF.Parameter&lt;T&gt; method may only be used within Entity Framework LINQ queries.</value>
</data>
<data name="EFParameterWithNonEvaluatableArgument" xml:space="preserve">
<value>The EF.Parameter&lt;T&gt; method may only be used with an argument that can be evaluated client-side and does not contain any reference to database-side entities.</value>
</data>
<data name="EmptyComplexType" xml:space="preserve">
<value>Complex type '{complexType}' has no properties defines. Configure at least one property or don't include this type in the model.</value>
</data>
Expand Down Expand Up @@ -624,6 +618,9 @@
<data name="HiLoBadBlockSize" xml:space="preserve">
<value>The block size used for Hi-Lo value generation is not positive. The Hi-Lo generator is usually backed by a SQL sequence and this means that the sequence increment must be positive.</value>
</data>
<data name="ChangeTrackingInterfaceMissing" xml:space="preserve">
<value>The entity type '{entityType}' is configured to use the '{changeTrackingStrategy}' change tracking strategy, but does not implement the required '{notificationInterface}' interface. Implement '{notificationInterface}' on '{entityType}' or use a different change tracking strategy.</value>
</data>
<data name="IdentifyingRelationshipCycle" xml:space="preserve">
<value>A relationship cycle involving the primary keys of the following entity types was detected: '{entityType}'. This would prevent any entity to be inserted without violating the store constraints. Review the foreign keys defined on the primary keys and either remove or use other properties for at least one of them.</value>
</data>
Expand Down
Loading
Loading