Skip to content

Commit

Permalink
Fix merge from 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Oct 5, 2023
1 parent 8fc207a commit 6a53a38
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 206 deletions.
8 changes: 4 additions & 4 deletions src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.Linq;
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;

// ReSharper disable once CheckNamespace
Expand All @@ -18,7 +16,9 @@ namespace Microsoft.EntityFrameworkCore;
public static class CosmosPropertyExtensions
{
private static readonly bool _useOldBehavior31664 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue31664", out var enabled31664) && enabled31664;/// <summary>
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue31664", out var enabled31664) && enabled31664;

/// <summary>
/// Returns the property name that the property is mapped to when targeting Cosmos.
/// </summary>
/// <param name="property">The property.</param>
Expand All @@ -39,7 +39,7 @@ private static string GetDefaultJsonPropertyName(IReadOnlyProperty property)
if (pk != null
&& (property.ClrType == typeof(int) || ownership.Properties.Contains(property))
&& (property.IsShadowProperty() || _useOldBehavior31664)
&& pk.Properties.Count == ownership.Properties.Count + (ownership.IsUnique ? 0 : 1)
&& pk.Properties.Count == ownership.Properties.Count + (ownership.IsUnique ? 0 : 1)
&& ownership.Properties.All(fkProperty => pk.Properties.Contains(fkProperty)))
{
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class CosmosValueGenerationConvention :
IEntityTypeAnnotationChangedConvention
{
private static readonly bool _useOldBehavior31664 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue31664", out var enabled31664) && enabled31664;/// <summary>
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue31664", out var enabled31664) && enabled31664;

/// <summary>
/// Creates a new instance of <see cref="CosmosValueGenerationConvention" />.
/// </summary>
/// <param name="dependencies">Parameter object containing dependencies for this convention.</param>
Expand Down Expand Up @@ -81,7 +83,7 @@ public virtual void ProcessEntityTypeAnnotationChanged(
if (pk != null
&& !property.IsForeignKey()
&& pk.Properties.Count == ownership.Properties.Count + 1
&& (property.IsShadowProperty() || _useOldBehavior31664)
&& (property.IsShadowProperty() || _useOldBehavior31664)
&& ownership.Properties.All(fkProperty => pk.Properties.Contains(fkProperty)))
{
return ValueGenerated.OnAddOrUpdate;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/Internal/NavigationFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ private void FindOrCreateJoinEntry(
else if (!_inAttachGraph)
{
var joinEntityType = arguments.SkipNavigation.JoinEntityType;
var joinEntity = _entityMaterializerSource.GetEmptyMaterializer(joinEntityType)
var joinEntity = joinEntityType.GetOrCreateEmptyMaterializer(_entityMaterializerSource)
(new MaterializationContext(ValueBuffer.Empty, arguments.Entry.Context));

joinEntry = arguments.Entry.StateManager.GetOrCreateEntry(joinEntity, joinEntityType);
Expand Down
13 changes: 6 additions & 7 deletions src/EFCore/Infrastructure/ModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,13 @@ protected virtual void ValidateInheritanceMapping(
protected virtual void ValidateDiscriminatorValues(IEntityType rootEntityType)
{
var derivedTypes = rootEntityType.GetDerivedTypesInclusive().ToList();


var discriminatorProperty = rootEntityType.FindDiscriminatorProperty();
if (discriminatorProperty == null){
if (derivedTypes.Count == 1)
{
return;
}
if (discriminatorProperty == null)
{
if (derivedTypes.Count == 1)
{
return;
}

throw new InvalidOperationException(
CoreStrings.NoDiscriminatorProperty(rootEntityType.DisplayName()));
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Conventions/RuntimeModelConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public virtual IModel ProcessModelFinalized(IModel model)
protected virtual RuntimeModel Create(IModel model)
{
var runtimeModel = new RuntimeModel();
runtimeModel.ModelId = model.ModelId;runtimeModel.SetSkipDetectChanges(((IRuntimeModel)model).SkipDetectChanges);
runtimeModel.ModelId = model.ModelId;
runtimeModel.SetSkipDetectChanges(((IRuntimeModel)model).SkipDetectChanges);
((IModel)runtimeModel).ModelDependencies = model.ModelDependencies!;

var entityTypes = model.GetEntityTypesInHierarchicalOrder();
Expand Down
46 changes: 18 additions & 28 deletions src/EFCore/Metadata/IReadOnlyEntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

using System.Text;
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 @@ -765,6 +762,24 @@ IReadOnlyProperty GetProperty(string name)
/// </summary>
IEnumerable<IReadOnlyTrigger> GetDeclaredTriggers();

/// <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>
/// 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> GetOrCreateEmptyMaterializer(IEntityMaterializerSource source);

/// <summary>
/// <para>
/// Creates a human-readable representation of the given metadata.
Expand All @@ -781,31 +796,6 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt
{
var builder = new StringBuilder();
var indentString = new string(' ', indent);
/// <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.
/// </para>
/// <para>
/// Warning: Do not rely on the format of the returned string.
/// It is designed for debugging only and may change arbitrarily between releases.
/// </para>
/// </summary>
/// <param name="options">Options for generating the string.</param>
/// <param name="indent">The number of indent spaces to use before each new line.</param>
/// <returns>A human-readable representation.</returns>
string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOptions.ShortDefault, int indent = 0)
{
var builder = new StringBuilder();
var indentString = new string(' ', indent);

try
{
Expand Down
18 changes: 9 additions & 9 deletions src/EFCore/Metadata/IReadOnlyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ private static int GetDerivedLevel(Type? derivedType, Dictionary<Type, int> deri
}

/// <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 Guid ModelId { get; }

/// <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 Guid ModelId { get; }

/// <summary>
/// <para>
/// Creates a human-readable representation of the given metadata.
/// </para>
Expand Down
33 changes: 19 additions & 14 deletions src/EFCore/Metadata/Internal/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
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;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal;

Expand Down Expand Up @@ -3580,16 +3575,26 @@ private void UpdateServiceOnlyConstructorBindingConfigurationSource(Configuratio
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);
/// 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
/// <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> GetOrCreateEmptyMaterializer(IEntityMaterializerSource source)
=> source.GetEmptyMaterializer(this);

#endregion

#region Explicit interface implementations

Expand Down
16 changes: 8 additions & 8 deletions src/EFCore/Metadata/Internal/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,14 @@ public virtual IEnumerable<EntityType> FindEntityTypes(Type type)
}

/// <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 virtual Guid ModelId { get; } = Guid.NewGuid();

/// <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 virtual Guid ModelId { get; } = Guid.NewGuid();

/// <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
Expand Down
49 changes: 30 additions & 19 deletions src/EFCore/Metadata/RuntimeEntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
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;

namespace Microsoft.EntityFrameworkCore.Metadata;

Expand Down Expand Up @@ -70,7 +66,8 @@ private readonly SortedDictionary<string, RuntimeTrigger> _triggers
private Func<ISnapshot>? _emptyShadowValuesFactory;
private IProperty[]? _foreignKeyProperties;
private IProperty[]? _valueGeneratingProperties;
private Func<MaterializationContext, object>? _materializer;
private Func<MaterializationContext, object>? _materializer;
private Func<MaterializationContext, object>? _emptyMaterializer;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -850,20 +847,34 @@ public virtual InstantiationBinding? ServiceOnlyConstructorBinding
=> 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>
/// 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>
/// 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> GetOrCreateEmptyMaterializer(IEntityMaterializerSource source)
=> EntityMaterializerSource.UseOldBehavior31866
? source.GetEmptyMaterializer(this)
: NonCapturingLazyInitializer.EnsureInitialized(
ref _emptyMaterializer, this, source,
static (e, s) => s.GetEmptyMaterializer(e));

/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>A string that represents the current object.</returns>
Expand Down
32 changes: 13 additions & 19 deletions src/EFCore/Metadata/RuntimeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ private IEnumerable<RuntimeEntityType> FindEntityTypes(Type type)
}

/// <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 Guid ModelId { get; set; }

/// <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 Guid ModelId { get; set; }

/// <summary>
/// Adds configuration for a scalar type.
/// </summary>
/// <param name="clrType">The type of value the property will hold.</param>
Expand Down Expand Up @@ -311,14 +311,8 @@ IEnumerable<ITypeMappingConfiguration> IModel.GetTypeMappingConfigurations()
=> _typeConfigurations.Count == 0
? null
: _typeConfigurations.GetValueOrDefault(propertyType);
/// <inheritdoc />
ITypeMappingConfiguration? IModel.FindTypeMappingConfiguration(Type propertyType)
=> _typeConfigurations.Count == 0
? null
: _typeConfigurations.GetValueOrDefault(propertyType);

/// <inheritdoc />
Guid IReadOnlyModel.ModelId
=> ModelId;
}

/// <inheritdoc />
Guid IReadOnlyModel.ModelId
=> ModelId;
}
Loading

0 comments on commit 6a53a38

Please sign in to comment.