Skip to content

Commit

Permalink
Revert "[release/6.0] Stop storing model references in the EntityMate…
Browse files Browse the repository at this point in the history
…rializerSource (#31943)"

This reverts commit 7fb644d.
  • Loading branch information
wtgodbe committed Oct 18, 2023
1 parent cb934d0 commit 113214d
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 71 deletions.
Expand Up @@ -312,7 +312,7 @@ private bool IsSpatialiteColumn(AddColumnOperation operation, IModel? model)
createTableOperation.PrimaryKey = AddPrimaryKeyOperation.CreateFrom(primaryKey);
}

foreach (var column in table.Columns.Where(c => c.Order.HasValue).OrderBy(c => c.Order!.Value)
foreach (var column in table.Columns.Where(c => c.Order.HasValue).OrderBy(c => c.Order.Value)
.Concat(table.Columns.Where(c => !c.Order.HasValue)))
{
if (!column.TryGetDefaultValue(out var defaultValue))
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/Internal/ArrayPropertyValues.cs
Expand Up @@ -42,7 +42,7 @@ public ArrayPropertyValues(InternalEntityEntry internalEntry, object?[] values)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override object ToObject()
=> EntityType.GetOrCreateMaterializer(MaterializerSource)(
=> MaterializerSource.GetMaterializer(EntityType)(
new MaterializationContext(
new ValueBuffer(_values),
InternalEntry.StateManager.Context));
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/Internal/StateManager.cs
Expand Up @@ -319,7 +319,7 @@ public virtual InternalEntityEntry CreateEntry(IDictionary<string, object?> valu
}

var valueBuffer = new ValueBuffer(valuesArray);
var entity = entityType.GetOrCreateMaterializer(EntityMaterializerSource)(new MaterializationContext(valueBuffer, Context));
var entity = EntityMaterializerSource.GetMaterializer(entityType)(new MaterializationContext(valueBuffer, Context));

var shadowPropertyValueBuffer = new ValueBuffer(shadowPropertyValuesArray);
var entry = new InternalEntityEntry(this, entityType, entity, shadowPropertyValueBuffer);
Expand Down
11 changes: 0 additions & 11 deletions src/EFCore/Metadata/IReadOnlyEntityType.cs
Expand Up @@ -12,8 +12,6 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Metadata
Expand Down Expand Up @@ -805,15 +803,6 @@ IReadOnlyProperty GetProperty(string name)
/// <returns>The service properties defined on this entity type.</returns>
IEnumerable<IReadOnlyServiceProperty> GetServiceProperties();

/// <summary>
/// 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.
/// </summary>
[EntityFrameworkInternal]
Func<MaterializationContext, object> GetOrCreateMaterializer(IEntityMaterializerSource source);

/// <summary>
/// <para>
/// Creates a human-readable representation of the given metadata.
Expand Down
11 changes: 0 additions & 11 deletions src/EFCore/Metadata/Internal/EntityType.cs
Expand Up @@ -13,7 +13,6 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -3552,16 +3551,6 @@ private void UpdateServiceOnlyConstructorBindingConfigurationSource(Configuratio
=> _serviceOnlyConstructorBindingConfigurationSource =
configurationSource.Max(_serviceOnlyConstructorBindingConfigurationSource);

/// <summary>
/// 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.
/// </summary>
[EntityFrameworkInternal]
public virtual Func<MaterializationContext, object> GetOrCreateMaterializer(IEntityMaterializerSource source)
=> source.GetMaterializer(this);

#endregion

#region Explicit interface implementations
Expand Down
17 changes: 0 additions & 17 deletions src/EFCore/Metadata/RuntimeEntityType.cs
Expand Up @@ -13,8 +13,6 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.EntityFrameworkCore.ValueGeneration;
Expand Down Expand Up @@ -74,7 +72,6 @@ public class RuntimeEntityType : AnnotatableBase, IRuntimeEntityType
private Func<MaterializationContext, object>? _instanceFactory;
private IProperty[]? _foreignKeyProperties;
private IProperty[]? _valueGeneratingProperties;
private Func<MaterializationContext, object>? _materializer;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -817,20 +814,6 @@ private IEnumerable<RuntimeServiceProperty> GetDerivedServiceProperties()
public static PropertyInfo? FindIndexerProperty(Type type)
=> type.FindIndexerProperty();

/// <summary>
/// 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.
/// </summary>
[EntityFrameworkInternal]
public virtual Func<MaterializationContext, object> GetOrCreateMaterializer(IEntityMaterializerSource source)
=> EntityMaterializerSource.UseOldBehavior31866
? source.GetMaterializer(this)
: NonCapturingLazyInitializer.EnsureInitialized(
ref _materializer, this, source,
static (e, s) => s.GetMaterializer(e));

/// <summary>
/// Returns a string that represents the current object.
/// </summary>
Expand Down
36 changes: 11 additions & 25 deletions src/EFCore/Query/Internal/EntityMaterializerSource.cs
Expand Up @@ -31,15 +31,6 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal
/// </summary>
public class EntityMaterializerSource : IEntityMaterializerSource
{
/// <summary>
/// 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.
/// </summary>
public static readonly bool UseOldBehavior31866 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue31866", out var enabled31866) && enabled31866;

private ConcurrentDictionary<IEntityType, Func<MaterializationContext, object>>? _materializers;

/// <summary>
Expand Down Expand Up @@ -155,21 +146,16 @@ static Expression CreateMemberAssignment(Expression parameter, MemberInfo member
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual Func<MaterializationContext, object> GetMaterializer(IEntityType entityType)
{
return UseOldBehavior31866
? Materializers.GetOrAdd(entityType, static (e, s) => CreateMaterializer(s, e), this)
: CreateMaterializer(this, entityType);

static Func<MaterializationContext, object> CreateMaterializer(EntityMaterializerSource self, IEntityType e)
{
var materializationContextParameter
= Expression.Parameter(typeof(MaterializationContext), "materializationContext");

return Expression.Lambda<Func<MaterializationContext, object>>(
self.CreateMaterializeExpression(e, "instance", materializationContextParameter),
materializationContextParameter)
.Compile();
}
}
=> Materializers.GetOrAdd(
entityType, e =>
{
var materializationContextParameter
= Expression.Parameter(typeof(MaterializationContext), "materializationContext");
return Expression.Lambda<Func<MaterializationContext, object>>(
CreateMaterializeExpression(e, "instance", materializationContextParameter),
materializationContextParameter)
.Compile();
});
}
}
Expand Up @@ -15,7 +15,6 @@
using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Update;
using Newtonsoft.Json;
Expand Down Expand Up @@ -563,9 +562,6 @@ public IEnumerable<IForeignKey> GetReferencingForeignKeys()
public IEnumerable<IServiceProperty> GetServiceProperties()
=> throw new NotImplementedException();

public Func<MaterializationContext, object> GetOrCreateMaterializer(IEntityMaterializerSource source)
=> throw new NotImplementedException();

public IEnumerable<ISkipNavigation> GetSkipNavigations()
=> throw new NotImplementedException();

Expand Down

0 comments on commit 113214d

Please sign in to comment.