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

Cleanup some of the internal API usage in Relational #20388

Merged
merged 1 commit into from
Mar 24, 2020
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 @@ -1044,12 +1044,12 @@ private Expression TryExpand(Expression source, MemberIdentity member)
.Select(p => p.ClrType)
.Any(t => t.IsNullableType());

var outerKey = entityShaperExpression.CreateKeyAccessExpression(
var outerKey = entityShaperExpression.CreateKeyValueReadExpression(
navigation.IsOnDependent
? foreignKey.Properties
: foreignKey.PrincipalKey.Properties,
makeNullable);
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyAccessExpression(
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValueReadExpression(
navigation.IsOnDependent
? foreignKey.PrincipalKey.Properties
: foreignKey.Properties,
Expand Down Expand Up @@ -1092,12 +1092,12 @@ ProjectionBindingExpression projectionBindingExpression
.Select(p => p.ClrType)
.Any(t => t.IsNullableType());

var outerKey = entityShaperExpression.CreateKeyAccessExpression(
var outerKey = entityShaperExpression.CreateKeyValueReadExpression(
navigation.IsOnDependent
? foreignKey.Properties
: foreignKey.PrincipalKey.Properties,
makeNullable);
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyAccessExpression(
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValueReadExpression(
navigation.IsOnDependent
? foreignKey.PrincipalKey.Properties
: foreignKey.Properties,
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public virtual InMemoryIntegerValueGenerator<TProperty> GetIntegerValueGenerator
_integerGenerators = new Dictionary<int, IInMemoryIntegerValueGenerator>();
}

// WARNING: The in-memory provider is using EF internal code here. This should not be copied by other providers. See #15096
var propertyIndex = EntityFrameworkCore.Metadata.Internal.PropertyBaseExtensions.GetIndex(property);
var propertyIndex = property.GetIndex();
if (!_integerGenerators.TryGetValue(propertyIndex, out var generator))
{
generator = new InMemoryIntegerValueGenerator<TProperty>(propertyIndex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class EntityFrameworkRelationalServicesBuilder : EntityFrameworkServicesB
/// </summary>
[EntityFrameworkInternal]
public static readonly IDictionary<Type, ServiceCharacteristics> RelationalServices
#pragma warning disable EF1001 // Internal EF Core API usage.
= new Dictionary<Type, ServiceCharacteristics>
{
{ typeof(IKeyValueIndexFactorySource), new ServiceCharacteristics(ServiceLifetime.Singleton) },
Expand Down Expand Up @@ -94,6 +95,7 @@ public static readonly IDictionary<Type, ServiceCharacteristics> RelationalServi
{ typeof(IMemberTranslatorPlugin), new ServiceCharacteristics(ServiceLifetime.Singleton, multipleRegistrations: true) },
{ typeof(IRelationalParameterBasedQueryTranslationPostprocessorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }
};
#pragma warning restore EF1001 // Internal EF Core API usage.

/// <summary>
/// Used by relational database providers to create a new <see cref="EntityFrameworkRelationalServicesBuilder" /> for
Expand All @@ -116,7 +118,9 @@ protected override ServiceCharacteristics GetServiceCharacteristics(Type service
{
return RelationalServices.TryGetValue(serviceType, out var characteristics)
? characteristics
#pragma warning disable EF1001 // Internal EF Core API usage.
: base.GetServiceCharacteristics(serviceType);
#pragma warning restore EF1001 // Internal EF Core API usage.
}

/// <summary>
Expand Down Expand Up @@ -173,6 +177,7 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
TryAdd<IRelationalParameterBasedQueryTranslationPostprocessorFactory, RelationalParameterBasedQueryTranslationPostprocessorFactory>();
TryAdd<IRelationalQueryStringFactory, RelationalQueryStringFactory>();

#pragma warning disable EF1001 // Internal EF Core API usage.
ServiceCollectionMap.GetInfrastructure()
.AddDependencySingleton<RelationalSqlGenerationHelperDependencies>()
.AddDependencySingleton<RelationalTypeMappingSourceDependencies>()
Expand Down Expand Up @@ -205,6 +210,7 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
.AddDependencyScoped<RelationalConnectionDependencies>()
.AddDependencyScoped<RelationalDatabaseDependencies>()
.AddDependencyScoped<RelationalQueryContextDependencies>();
#pragma warning restore EF1001 // Internal EF Core API usage.

return base.TryAddCoreServices();
}
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Infrastructure/ModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ public abstract class ModelSnapshot

private IModel CreateModel()
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var model = new Model();
var modelBuilder = new ModelBuilder(model);

BuildModel(modelBuilder);

return model;
#pragma warning restore EF1001 // Internal EF Core API usage.
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ protected virtual void ValidateInheritanceMapping(
foreach (var entityType in model.GetEntityTypes())
{
if (entityType.BaseType != null
&& ((EntityType)entityType).FindAnnotation(RelationalAnnotationNames.TableName)?.GetConfigurationSource()
&& ((IConventionEntityType)entityType).FindAnnotation(RelationalAnnotationNames.TableName)?.GetConfigurationSource()
== ConfigurationSource.Explicit)
{
throw new InvalidOperationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ private static void TryUniquifyColumnNames(
continue;
}

var identifyingMemberInfo = property.GetIdentifyingMemberInfo();
var identifyingMemberInfo = property.PropertyInfo ?? (MemberInfo)property.FieldInfo;
if (identifyingMemberInfo != null
&& identifyingMemberInfo.IsSameAs(otherProperty.GetIdentifyingMemberInfo()))
&& identifyingMemberInfo.IsSameAs(otherProperty.PropertyInfo ?? (MemberInfo)otherProperty.FieldInfo))
{
continue;
}
Expand Down
1 change: 0 additions & 1 deletion src/EFCore.Relational/Metadata/IColumnBase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Infrastructure;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/Internal/TableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/Internal/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
{
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Migrations/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ public virtual IModel TargetModel
{
IModel Create()
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var model = new Model();
var modelBuilder = new ModelBuilder(model);
BuildTargetModel(modelBuilder);

model = (Model)RelationalModel.Add(model, null);
return model.FinalizeModel();
#pragma warning restore EF1001 // Internal EF Core API usage.
}

return _targetModel ??= Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Migrations.Internal;
using Microsoft.EntityFrameworkCore.Update;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -1186,12 +1185,12 @@ private Expression TryExpand(Expression source, MemberIdentity member)
var innerSequenceType = innerShapedQuery.Type.TryGetSequenceType();
var correlationPredicateParameter = Expression.Parameter(innerSequenceType);

var outerKey = entityShaperExpression.CreateKeyAccessExpression(
var outerKey = entityShaperExpression.CreateKeyValueReadExpression(
navigation.IsOnDependent
? foreignKey.Properties
: foreignKey.PrincipalKey.Properties,
makeNullable);
var innerKey = correlationPredicateParameter.CreateKeyAccessExpression(
var innerKey = correlationPredicateParameter.CreateKeyValueReadExpression(
navigation.IsOnDependent
? foreignKey.PrincipalKey.Properties
: foreignKey.Properties,
Expand Down Expand Up @@ -1247,12 +1246,12 @@ private Expression TryExpand(Expression source, MemberIdentity member)
.Select(p => p.ClrType)
.Any(t => t.IsNullableType());

var outerKey = entityShaperExpression.CreateKeyAccessExpression(
var outerKey = entityShaperExpression.CreateKeyValueReadExpression(
navigation.IsOnDependent
? foreignKey.Properties
: foreignKey.PrincipalKey.Properties,
makeNullable);
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyAccessExpression(
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValueReadExpression(
navigation.IsOnDependent
? foreignKey.PrincipalKey.Properties
: foreignKey.Properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
Expand Down
19 changes: 19 additions & 0 deletions src/EFCore/Extensions/ConventionEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public static class ConventionEntityTypeExtensions
public static IConventionEntityType GetRootType([NotNull] this IConventionEntityType entityType)
=> (IConventionEntityType)((IEntityType)entityType).GetRootType();

/// <summary>
/// Gets all types in the model which a given entity type derives from.
/// </summary>
/// <param name="entityType"> The type to find base types. </param>
/// <returns>
/// The base types.
/// </returns>
public static IEnumerable<IConventionEntityType> GetAllBaseTypes([NotNull] this IConventionEntityType entityType)
=> entityType.GetAllBaseTypesAscending().Reverse().Cast<IConventionEntityType>();

/// <summary>
/// Gets all types in the model that derive from a given entity type.
/// </summary>
Expand Down Expand Up @@ -79,6 +89,15 @@ public static IEnumerable<IConventionEntityType> GetAllBaseTypesInclusiveAscendi
}
}


/// <summary>
/// Returns all types in hierarchy of the given <see cref="IConventionEntityType" />.
/// </summary>
/// <param name="entityType"> The entity type. </param>
/// <returns> All types in the hierarchy. </returns>
public static IEnumerable<IConventionEntityType> GetTypesInHierarchy([NotNull] this IConventionEntityType entityType)
=> entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()).Cast<IConventionEntityType>();

/// <summary>
/// <para>
/// Gets all keys declared on the given <see cref="IEntityType" />.
Expand Down
Loading