Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove quirks from main #26711

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -36,10 +36,6 @@ private static readonly PropertyInfo _jTokenTypePropertyInfo
= typeof(JToken).GetRuntimeProperties()
.Single(mi => mi.Name == nameof(JToken.Type));

private static readonly MethodInfo _jTokenToObjectMethodInfo
= typeof(JToken).GetRuntimeMethods()
.Single(mi => mi.Name == nameof(JToken.ToObject) && mi.GetParameters().Length == 0);

private static readonly MethodInfo _jTokenToObjectWithSerializerMethodInfo
= typeof(JToken).GetRuntimeMethods()
.Single(mi => mi.Name == nameof(JToken.ToObject) && mi.GetParameters().Length == 1 && mi.IsGenericMethodDefinition);
Expand Down Expand Up @@ -70,12 +66,6 @@ private readonly IDictionary<Expression, Expression> _ordinalParameterBindings
private List<IncludeExpression> _pendingIncludes
= new();

private readonly bool _useOldBehavior;

private static readonly MethodInfo _toObjectMethodInfo
= typeof(CosmosProjectionBindingRemovingExpressionVisitorBase)
.GetRuntimeMethods().Single(mi => mi.Name == nameof(SafeToObject));

private static readonly MethodInfo _toObjectWithSerializerMethodInfo
= typeof(CosmosProjectionBindingRemovingExpressionVisitorBase)
.GetRuntimeMethods().Single(mi => mi.Name == nameof(SafeToObjectWithSerializer));
Expand All @@ -86,7 +76,6 @@ public CosmosProjectionBindingRemovingExpressionVisitorBase(
{
_jObjectParameter = jObjectParameter;
_trackQueryResults = trackQueryResults;
_useOldBehavior = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26690", out var enabled) && enabled;
}

protected override Expression VisitBinary(BinaryExpression binaryExpression)
Expand All @@ -109,7 +98,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
storeName = projection.Alias;
}
else if (projectionExpression is UnaryExpression convertExpression
&& convertExpression.NodeType == ExpressionType.Convert)
&& convertExpression.NodeType == ExpressionType.Convert)
{
// Unwrap EntityProjectionExpression when the root entity is not projected
projectionExpression = ((UnaryExpression)convertExpression.Operand).Operand;
Expand Down Expand Up @@ -710,14 +699,10 @@ private Expression CreateGetValueExpression(
var body
= ReplacingExpressionVisitor.Replace(
converter.ConvertFromProviderExpression.Parameters.Single(),
_useOldBehavior
? Expression.Call(
jTokenParameter,
_jTokenToObjectMethodInfo.MakeGenericMethod(converter.ProviderClrType))
: Expression.Call(
jTokenParameter,
_jTokenToObjectWithSerializerMethodInfo.MakeGenericMethod(converter.ProviderClrType),
Expression.Constant(CosmosClientWrapper.Serializer)),
Expression.Call(
jTokenParameter,
_jTokenToObjectWithSerializerMethodInfo.MakeGenericMethod(converter.ProviderClrType),
Expression.Constant(CosmosClientWrapper.Serializer)),
converter.ConvertFromProviderExpression.Body);

if (body.Type != type)
Expand Down Expand Up @@ -771,9 +756,7 @@ private Expression ConvertJTokenToType(Expression jTokenExpression, Type type)
=> type == typeof(JToken)
? jTokenExpression
: Expression.Call(
_useOldBehavior
? _toObjectMethodInfo.MakeGenericMethod(type)
ajcvickers marked this conversation as resolved.
Show resolved Hide resolved
: _toObjectWithSerializerMethodInfo.MakeGenericMethod(type),
_toObjectWithSerializerMethodInfo.MakeGenericMethod(type),
jTokenExpression);

private static T SafeToObject<T>(JToken token)
Expand Down
29 changes: 10 additions & 19 deletions src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,16 +2620,10 @@ private SqlRemappingVisitor PushdownIntoSubqueryInternal()
_tables.Add(subquery);
_tableReferences.Add(subqueryTableReferenceExpression);

var useOldBehavior = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26587", out var enabled)
&& enabled;

if (!useOldBehavior)
// Remap tableReferences in inner so that all components follow referential integrity.
foreach (var tableReference in subquery._tableReferences)
{
// Remap tableReferences in inner so that all components follow referential integrity.
foreach (var tableReference in subquery._tableReferences)
{
tableReference.UpdateTableReference(this, subquery);
}
tableReference.UpdateTableReference(this, subquery);
}

var projectionMap = new Dictionary<SqlExpression, ColumnExpression>(ReferenceEqualityComparer.Instance);
Expand Down Expand Up @@ -2747,8 +2741,8 @@ private SqlRemappingVisitor PushdownIntoSubqueryInternal()
_orderings.Add(ordering.Update(outerColumn));
}
else if (!IsDistinct
&& GroupBy.Count == 0
|| GroupBy.Contains(orderingExpression))
&& GroupBy.Count == 0
|| GroupBy.Contains(orderingExpression))
{
_orderings.Add(
ordering.Update(
Expand All @@ -2768,13 +2762,10 @@ private SqlRemappingVisitor PushdownIntoSubqueryInternal()
subquery.ClearOrdering();
}

if (useOldBehavior)
// Remap tableReferences in inner
foreach (var tableReference in subquery._tableReferences)
{
// Remap tableReferences in inner
foreach (var tableReference in subquery._tableReferences)
{
tableReference.UpdateTableReference(this, subquery);
}
tableReference.UpdateTableReference(this, subquery);
}

var tableReferenceUpdatingExpressionVisitor = new TableReferenceUpdatingExpressionVisitor(this, subquery);
Expand Down Expand Up @@ -2819,8 +2810,8 @@ EntityProjectionExpression LiftEntityProjectionFromSubquery(EntityProjectionExpr

// Also lift nested entity projections
foreach (var navigation in entityProjection.EntityType
.GetAllBaseTypes().Concat(entityProjection.EntityType.GetDerivedTypesInclusive())
.SelectMany(t => t.GetDeclaredNavigations()))
.GetAllBaseTypes().Concat(entityProjection.EntityType.GetDerivedTypesInclusive())
.SelectMany(t => t.GetDeclaredNavigations()))
{
var boundEntityShaperExpression = entityProjection.BindNavigation(navigation);
if (boundEntityShaperExpression != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public virtual ResultSetMapping AppendBulkInsertOperation(
modificationCommands[0],
modificationCommands[0].ColumnModifications.Where(o => o.IsKey).ToList(),
modificationCommands[0].ColumnModifications.Where(o => o.IsRead).ToList(),
(!AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26632", out var enabled) || !enabled)
? commandPosition
: 0);
commandPosition);
}

var readOperations = modificationCommands[0].ColumnModifications.Where(o => o.IsRead).ToList();
Expand Down
25 changes: 2 additions & 23 deletions src/EFCore/Metadata/Internal/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,18 +826,8 @@ public virtual CoreTypeMapping? TypeMapping
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual ValueComparer? GetValueComparer()
{
if (!(AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26629", out var enabled)
&& enabled))
{
return GetValueComparer(new HashSet<IProperty>())
?? TypeMapping?.Comparer;
}

return (ValueComparer?)this[CoreAnnotationNames.ValueComparer]
?? FindFirstDifferentPrincipal()?.GetValueComparer()
=> GetValueComparer(null)
?? TypeMapping?.Comparer;
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -846,18 +836,8 @@ public virtual CoreTypeMapping? TypeMapping
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual ValueComparer? GetKeyValueComparer()
{
if (!(AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26629", out var enabled)
&& enabled))
{
return GetValueComparer(new HashSet<IProperty>())
?? TypeMapping?.KeyComparer;
}

return (ValueComparer?)this[CoreAnnotationNames.ValueComparer]
?? FindFirstDifferentPrincipal()?.GetKeyValueComparer()
=> GetValueComparer(null)
?? TypeMapping?.KeyComparer;
}

private ValueComparer? GetValueComparer(HashSet<IProperty>? checkedProperties)
{
Expand Down Expand Up @@ -1041,7 +1021,6 @@ public static bool AreCompatible(IReadOnlyList<Property> properties, EntityType
property =>
property.IsShadowProperty()
|| (property.IsIndexerProperty()
&& (!AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26590", out var enabled) || !enabled)
? property.PropertyInfo == entityType.FindIndexerPropertyInfo()
: ((property.PropertyInfo != null
&& entityType.GetRuntimeProperties().ContainsKey(property.Name))
Expand Down
74 changes: 10 additions & 64 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ internal class SqliteConnectionFactory
{
public static readonly SqliteConnectionFactory Instance = new();

private readonly bool _newLockingBehavior;
#pragma warning disable IDE0052 // Remove unread private members
private readonly Timer _pruneTimer;
#pragma warning restore IDE0052 // Remove unread private members
Expand All @@ -23,13 +22,8 @@ internal class SqliteConnectionFactory

protected SqliteConnectionFactory()
{
_newLockingBehavior = !AppContext.TryGetSwitch("Microsoft.Data.Sqlite.Issue26612", out var enabled) || !enabled;

if (!AppContext.TryGetSwitch("Microsoft.Data.Sqlite.Issue26422", out enabled) || !enabled)
{
AppDomain.CurrentDomain.DomainUnload += (_, _) => ClearPools();
AppDomain.CurrentDomain.ProcessExit += (_, _) => ClearPools();
}
AppDomain.CurrentDomain.DomainUnload += (_, _) => ClearPools();
AppDomain.CurrentDomain.ProcessExit += (_, _) => ClearPools();

_pruneTimer = new Timer(PruneCallback, null, TimeSpan.FromMinutes(4), TimeSpan.FromSeconds(30));
}
Expand All @@ -56,10 +50,7 @@ public SqliteConnectionInternal GetConnection(SqliteConnection outerConnection)

public SqliteConnectionPoolGroup GetPoolGroup(string connectionString)
{
if (_newLockingBehavior)
{
_lock.EnterUpgradeableReadLock();
}
_lock.EnterUpgradeableReadLock();

try
{
Expand All @@ -69,14 +60,7 @@ public SqliteConnectionPoolGroup GetPoolGroup(string connectionString)
{
var connectionOptions = new SqliteConnectionStringBuilder(connectionString);

if (_newLockingBehavior)
{
_lock.EnterWriteLock();
}
else
{
Monitor.Enter(this);
}
_lock.EnterWriteLock();

try
{
Expand All @@ -93,25 +77,15 @@ public SqliteConnectionPoolGroup GetPoolGroup(string connectionString)
}
finally
{
if (_newLockingBehavior)
{
_lock.ExitWriteLock();
}
else
{
Monitor.Exit(this);
}
_lock.ExitWriteLock();
}
}

return poolGroup;
}
finally
{
if (_newLockingBehavior)
{
_lock.ExitUpgradeableReadLock();
}
_lock.ExitUpgradeableReadLock();
}
}

Expand All @@ -132,14 +106,7 @@ public void ReleasePool(SqliteConnectionPool pool, bool clearing)

public void ClearPools()
{
if (_newLockingBehavior)
{
_lock.EnterWriteLock();
}
else
{
Monitor.Enter(this);
}
_lock.EnterWriteLock();

try
{
Expand All @@ -150,14 +117,7 @@ public void ClearPools()
}
finally
{
if (_newLockingBehavior)
{
_lock.ExitWriteLock();
}
else
{
Monitor.Exit(this);
}
_lock.ExitWriteLock();
}
}

Expand Down Expand Up @@ -188,14 +148,7 @@ private void PruneCallback(object? _)
}
}

if (_newLockingBehavior)
{
_lock.EnterWriteLock();
}
else
{
Monitor.Enter(this);
}
_lock.EnterWriteLock();

try
{
Expand All @@ -218,14 +171,7 @@ private void PruneCallback(object? _)
}
finally
{
if (_newLockingBehavior)
{
_lock.ExitWriteLock();
}
else
{
Monitor.Exit(this);
}
_lock.ExitWriteLock();
}
}
}
Expand Down