Skip to content

Commit

Permalink
Adjust some exception messages
Browse files Browse the repository at this point in the history
Part of dotnet#31679
  • Loading branch information
roji committed Sep 12, 2023
1 parent cc6c986 commit 69ee7b2
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 10 deletions.

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.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
<data name="CannotChangeWhenOpen" xml:space="preserve">
<value>The instance of DbConnection is currently in use. The connection can only be changed when the existing connection is not being used.</value>
</data>
<data name="CannotCompareComplexTypeToNull" xml:space="preserve">
<value>Comparing complex types to null is not supported.</value>
</data>
<data name="CannotConfigureTriggerNonRootTphEntity" xml:space="preserve">
<value>Can't configure a trigger on entity type '{entityType}', which is in a TPH hierarchy and isn't the root. Configure the trigger on the TPH root entity type '{rootEntityType}' instead.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ bool TryRewriteComplexTypeEquality([NotNullWhen(true)] out Expression? result)
{
// TODO: when we support optional complex types - or projecting required complex types via optional navigations - we'll
// be able to translate this.
throw new InvalidOperationException(); // TODO: Message
throw new InvalidOperationException(RelationalStrings.CannotCompareComplexTypeToNull);
}

var leftComplexType = leftReference?.StructuralType as IComplexType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public virtual void AddNavigationBinding(INavigation navigation, StructuralTypeS
{
if (StructuralType is not IEntityType entityType)
{
throw new InvalidOperationException(); // TODO: Message
throw new UnreachableException("Navigations are only supported on entity types");
}

if (!entityType.IsAssignableFrom(navigation.DeclaringEntityType)
Expand All @@ -330,7 +330,7 @@ public virtual void AddNavigationBinding(INavigation navigation, StructuralTypeS
{
if (StructuralType is not IEntityType entityType)
{
throw new InvalidOperationException(); // TODO: Message
throw new UnreachableException("Navigations are only supported on entity types");
}

if (!entityType.IsAssignableFrom(navigation.DeclaringEntityType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,14 @@ protected virtual SqlServerOpenJsonExpression ApplyTypeMappingsOnOpenJsonExpress

// First, find the collection type mapping and apply it to the parameter
if (_typeMappingSource.FindMapping(parameterExpression.Type, Model, elementTypeMapping) is not SqlServerStringTypeMapping
parameterTypeMapping)
{
ElementTypeMapping: not null
}
parameterTypeMapping)
{
// TODO: Message
throw new InvalidOperationException("Type mapping for 'string' could not be found or was not a SqlServerStringTypeMapping");
throw new UnreachableException("A SqlServerStringTypeMapping collection type mapping could not be found");
}

Check.DebugAssert(parameterTypeMapping.ElementTypeMapping != null, "Collection type mapping missing element mapping.");

return openJsonExpression.Update(
parameterExpression.ApplyTypeMapping(parameterTypeMapping),
path: null,
Expand Down
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 Microsoft.EntityFrameworkCore.TestModels.ComplexTypeModel;

namespace Microsoft.EntityFrameworkCore.Query;

public abstract class ComplexTypeQueryRelationalTestBase<TFixture> : ComplexTypeQueryTestBase<TFixture>
Expand All @@ -18,6 +16,8 @@ public override async Task Subquery_over_complex_type(bool async)
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() => base.Subquery_over_complex_type(async));

Assert.Equal(RelationalStrings.SubqueryOverComplexTypesNotSupported("Customer.ShippingAddress#Address"), exception.Message);

AssertSql();
}

public override async Task Concat_two_different_complex_type(bool async)
Expand All @@ -27,6 +27,8 @@ public override async Task Concat_two_different_complex_type(bool async)
Assert.Equal(
RelationalStrings.SetOperationOverDifferentStructuralTypes(
"Customer.ShippingAddress#Address", "Customer.BillingAddress#Address"), exception.Message);

AssertSql();
}

public override async Task Union_two_different_complex_type(bool async)
Expand All @@ -36,5 +38,19 @@ public override async Task Union_two_different_complex_type(bool async)
Assert.Equal(
RelationalStrings.SetOperationOverDifferentStructuralTypes(
"Customer.ShippingAddress#Address", "Customer.BillingAddress#Address"), exception.Message);

AssertSql();
}

public override async Task Complex_type_equals_null(bool async)
{
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() => base.Complex_type_equals_null(async));

Assert.Equal(RelationalStrings.CannotCompareComplexTypeToNull, exception.Message);

AssertSql();
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ public virtual Task Complex_type_equals_parameter(bool async)
ss => ss.Set<Customer>().Where(c => c.ShippingAddress == address));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_type_equals_null(bool async)
=> AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => c.ShippingAddress == null));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Subquery_over_complex_type(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ FROM [Customer] AS [c]
""");
}

public override async Task Complex_type_equals_null(bool async)
{
await base.Complex_type_equals_null(async);

AssertSql();
}

public override async Task Subquery_over_complex_type(bool async)
{
await base.Subquery_over_complex_type(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ public override async Task Complex_type_equals_parameter(bool async)
""");
}

public override async Task Complex_type_equals_null(bool async)
{
await base.Complex_type_equals_null(async);

AssertSql();
}

public override async Task Subquery_over_complex_type(bool async)
{
await base.Subquery_over_complex_type(async);
Expand Down

0 comments on commit 69ee7b2

Please sign in to comment.