Skip to content

Commit

Permalink
Fixups for #23381 and #23376
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Nov 21, 2020
1 parent e45256e commit f6d0c6a
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 94 deletions.
1 change: 0 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ when sqlUnaryExpression.IsLogicalNot():
throw new InvalidOperationException(
CosmosStrings.UnsupportedOperatorForSqlExpression(
sqlUnaryExpression.OperatorType, typeof(SqlUnaryExpression).ShortDisplayName()));
;
}

return new SqlUnaryExpression(sqlUnaryExpression.OperatorType, operand, resultType, resultTypeMapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)

var property = member.MemberInfo != null
? entityType.FindProperty(member.MemberInfo)
: entityType.FindProperty(member.Name!);
: entityType.FindProperty(member.Name);

if (property != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ protected override Expression VisitExtension(Expression extensionExpression)

var navigation = member.MemberInfo != null
? entityType.FindNavigation(member.MemberInfo)
: entityType.FindNavigation(member.Name!);
: entityType.FindNavigation(member.Name);

if (navigation == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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;
using Microsoft.EntityFrameworkCore.Diagnostics;
Expand Down Expand Up @@ -44,9 +45,7 @@ public static bool AreCompatible(
var columnNames = foreignKey.Properties.GetColumnNames(storeObject);
var duplicateColumnNames = duplicateForeignKey.Properties.GetColumnNames(storeObject);
if (columnNames is null
|| duplicateColumnNames is null
|| principalTable is null
|| duplicatePrincipalTable is null)
|| duplicateColumnNames is null)
{
if (shouldThrow)
{
Expand All @@ -66,11 +65,13 @@ public static bool AreCompatible(
return false;
}

var principalColumns = foreignKey.PrincipalKey.Properties.GetColumnNames(principalTable.Value);
var duplicatePrincipalColumns = duplicateForeignKey.PrincipalKey.Properties.GetColumnNames(principalTable.Value);
if (principalTable != duplicatePrincipalTable
|| principalColumns == null
|| duplicatePrincipalColumns == null)
if (principalTable is null
|| duplicatePrincipalTable is null
|| principalTable != duplicatePrincipalTable
|| !(foreignKey.PrincipalKey.Properties.GetColumnNames(principalTable.Value)
is IReadOnlyList<string> principalColumns)
|| !(duplicateForeignKey.PrincipalKey.Properties.GetColumnNames(principalTable.Value)
is IReadOnlyList<string> duplicatePrincipalColumns))
{
if (shouldThrow)
{
Expand All @@ -81,7 +82,9 @@ public static bool AreCompatible(
duplicateForeignKey.Properties.Format(),
duplicateForeignKey.DeclaringEntityType.DisplayName(),
foreignKey.DeclaringEntityType.GetSchemaQualifiedTableName(),
foreignKey.GetConstraintName(storeObject, principalTable.Value),
principalTable.HasValue
? foreignKey.GetConstraintName(storeObject, principalTable.Value)
: foreignKey.GetDefaultName(),
principalType.GetSchemaQualifiedTableName(),
duplicatePrincipalType.GetSchemaQualifiedTableName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ protected override Expression VisitExtension(Expression extensionExpression)

var navigation = member.MemberInfo != null
? entityType.FindNavigation(member.MemberInfo)
: entityType.FindNavigation(member.Name!);
: entityType.FindNavigation(member.Name);

if (navigation == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
var entityType = entityReferenceExpression.EntityType;
var property = member.MemberInfo != null
? entityType.FindProperty(member.MemberInfo)
: entityType.FindProperty(member.Name!);
: entityType.FindProperty(member.Name);

if (property != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ public virtual Navigation AddNavigation(

private Navigation AddNavigation(MemberIdentity navigationMember, ForeignKey foreignKey, bool pointsToPrincipal)
{
var name = navigationMember.Name!;
var name = navigationMember.Name;
var duplicateNavigation = FindNavigationsInHierarchy(name).FirstOrDefault();
if (duplicateNavigation != null)
{
Expand Down
12 changes: 8 additions & 4 deletions src/EFCore/Metadata/MemberIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;

#nullable enable

Expand Down Expand Up @@ -55,7 +56,7 @@ public bool IsNone()
/// <summary>
/// A <see cref="MemberIdentity" /> instance that does not represent any member.
/// </summary>
public static readonly MemberIdentity None = new MemberIdentity((object?)null);
public static readonly MemberIdentity None = new((object?)null);

/// <summary>
/// Creates a new <see cref="MemberIdentity" /> from the given member name.
Expand All @@ -78,9 +79,12 @@ public static MemberIdentity Create([CanBeNull] MemberInfo? memberInfo)
/// <summary>
/// The name of the member.
/// </summary>
public string? Name
/// <exception cref="InvalidOperationException"> The <see cref="MemberIdentity"/> is empty. </exception>
public string Name
{
[DebuggerStepThrough] get => MemberInfo?.GetSimpleMemberName() ?? (string?)_nameOrMember;
[DebuggerStepThrough] get => MemberInfo?.GetSimpleMemberName()
?? (string?)_nameOrMember
?? throw new InvalidOperationException(CoreStrings.MemberIdentityIsEmpty);
}

/// <summary>
Expand All @@ -92,7 +96,7 @@ public MemberInfo? MemberInfo
}

private string DebuggerDisplay()
=> Name ?? "NONE";
=> IsNone() ? "NONE" : Name;

/// <inheritdoc />
public override bool Equals(object? obj)
Expand Down
6 changes: 6 additions & 0 deletions src/EFCore/Properties/CoreStrings.Designer.cs

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

3 changes: 3 additions & 0 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,9 @@
<value>'{contextType}' generated value '{keyValue}' for the property '{3_entityType}.{2_property}'.</value>
<comment>Debug CoreEventId.ValueGenerated string object string string</comment>
</data>
<data name="MemberIdentityIsEmpty" xml:space="preserve">
<value>An empty 'MemberIdentity' has been passed in a context which does not support it.</value>
</data>
<data name="MissingBackingField" xml:space="preserve">
<value>The specified field '{field}' could not be found for property '{2_entityType}.{1_property}'.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,15 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp

var navigation = memberIdentity.MemberInfo != null
? entityType.FindNavigation(memberIdentity.MemberInfo)
: entityType.FindNavigation(memberIdentity.Name!);
: entityType.FindNavigation(memberIdentity.Name);
if (navigation != null)
{
return ExpandNavigation(root, entityReference, navigation, convertedType != null);
}

var skipNavigation = memberIdentity.MemberInfo != null
? entityType.FindSkipNavigation(memberIdentity.MemberInfo)
: memberIdentity.Name is not null
? entityType.FindSkipNavigation(memberIdentity.Name)
: null;
: entityType.FindSkipNavigation(memberIdentity.Name);
if (skipNavigation != null)
{
return ExpandSkipNavigation(root, entityReference, skipNavigation, convertedType != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ protected override Assembly TargetAssembly

public class CosmosApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = b => CosmosTestHelpers.Instance.UseProviderOptions(b);

return true;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type>
{
typeof(CosmosModelBuilderExtensions),
Expand Down
7 changes: 0 additions & 7 deletions test/EFCore.Design.Tests/DesignApiConsistencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ protected override Assembly TargetAssembly

public class DesignApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = b => InMemoryTestHelpers.Instance.UseProviderOptions(b);

return true;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type> { typeof(DesignTimeServiceCollectionExtensions) };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ protected override Assembly TargetAssembly

public class InMemoryApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = b => InMemoryTestHelpers.Instance.UseProviderOptions(b);

return true;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type>
{
typeof(InMemoryServiceCollectionExtensions),
Expand Down
7 changes: 0 additions & 7 deletions test/EFCore.Proxies.Tests/ProxiesApiConsistencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ protected override Assembly TargetAssembly

public class ProxiesApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = b => InMemoryTestHelpers.Instance.UseProviderOptions(b);

return true;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type> { typeof(ProxiesServiceCollectionExtensions) };
}
}
Expand Down
6 changes: 0 additions & 6 deletions test/EFCore.Relational.Tests/RelationalApiConsistencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ public void Readonly_relational_metadata_methods_have_expected_name()

public class RelationalApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = null;
return false;
}

private static Dictionary<Type, (Type Mutable, Type Convention, Type ConventionBuilder)> _metadataTypes
=> new Dictionary<Type, (Type, Type, Type)>
{
Expand Down
10 changes: 7 additions & 3 deletions test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,13 @@ where ns.StartsWith("Microsoft.Entity", StringComparison.Ordinal)
&& !it.Name.EndsWith("Dependencies", StringComparison.Ordinal)
&& (it.GetConstructors().Length != 1
|| it.GetConstructors()[0].GetParameters().Length == 0
|| it.GetConstructors()[0].GetParameters()[0].Name != "dependencies")
|| it.GetConstructors()[0].GetParameters()[0].Name != "dependencies"
// Check that the parameter has a non-public copy constructor, identifying C# 9 records
|| !it.GetConstructors()[0].GetParameters()[0].ParameterType
.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)
.Any(c => c.GetParameters() is var parameters
&& parameters.Length == 1
&& parameters[0].Name == "original"))
select it)
.ToList();

Expand Down Expand Up @@ -900,8 +906,6 @@ protected ApiConsistencyFixtureBase()
Initialize();
}

public abstract bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions);

public virtual HashSet<Type> FluentApiTypes { get; } = new HashSet<Type>();

public virtual Dictionary<Type, Type> GenericFluentApiTypes { get; } = new Dictionary<Type, Type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ protected override Assembly TargetAssembly

public class SqlServerApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = b => SqlServerTestHelpers.Instance.UseProviderOptions(b);

return true;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type>
{
typeof(SqlServerDbContextOptionsBuilder),
Expand Down
7 changes: 0 additions & 7 deletions test/EFCore.SqlServer.Tests/SqlServerNTSApiConsistencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ protected override Assembly TargetAssembly

public class SqlServerNTSApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = b => SqlServerTestHelpers.Instance.UseProviderOptions(b);

return true;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type>
{
typeof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ protected override Assembly TargetAssembly

public class SqliteApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = b => SqliteTestHelpers.Instance.UseProviderOptions(b);

return true;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type>
{
typeof(SqliteServiceCollectionExtensions),
Expand Down
7 changes: 0 additions & 7 deletions test/EFCore.Sqlite.Tests/SqliteNTSApiConsistencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ protected override Assembly TargetAssembly

public class SqliteNTSApiConsistencyFixture : ApiConsistencyFixtureBase
{
public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = b => SqliteTestHelpers.Instance.UseProviderOptions(b);

return true;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type>
{
typeof(SqliteNetTopologySuiteDbContextOptionsBuilderExtensions),
Expand Down
6 changes: 0 additions & 6 deletions test/EFCore.Tests/ApiConsistencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ protected override void Initialize()
base.Initialize();
}

public override bool TryGetProviderOptionsDelegate(out Action<DbContextOptionsBuilder> configureOptions)
{
configureOptions = null;
return false;
}

public override HashSet<Type> FluentApiTypes { get; } = new HashSet<Type>
{
typeof(ModelBuilder),
Expand Down

0 comments on commit f6d0c6a

Please sign in to comment.