Skip to content

Commit

Permalink
Turn off automatic client evaluation of queries
Browse files Browse the repository at this point in the history
Issue #14935

* Tests are disabled if their primary purpose is to test queries.
* Queries are re-written if the purpose of the test was not primarily to test the query.
* All are tagged with this issue number so they can easily be found.
  • Loading branch information
ajcvickers committed Mar 7, 2019
1 parent f337568 commit e09c232
Show file tree
Hide file tree
Showing 67 changed files with 757 additions and 538 deletions.
4 changes: 3 additions & 1 deletion src/EFCore/Infrastructure/CoreOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ private WarningsConfiguration _warningsConfiguration
= new WarningsConfiguration()
.TryWithExplicit(CoreEventId.ManyServiceProvidersCreatedWarning, WarningBehavior.Throw)
.TryWithExplicit(CoreEventId.LazyLoadOnDisposedContextWarning, WarningBehavior.Throw)
.TryWithExplicit(CoreEventId.DetachedLazyLoadingWarning, WarningBehavior.Throw);
.TryWithExplicit(CoreEventId.DetachedLazyLoadingWarning, WarningBehavior.Throw)
// This is relational client eval warning. Yes, this is ugly and error-prone, but it will be removed before 3.0 ships
.TryWithExplicit(CoreEventId.RelationalBaseId + 500, WarningBehavior.Throw);

/// <summary>
/// Creates a new set of options with everything set to default values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public virtual async Task From_sql_queryable_stored_procedure_with_parameter()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'where [mep].TenMostExpensiveProducts.Contains(\"C\")'")]
public virtual async Task From_sql_queryable_stored_procedure_composed()
{
using (var context = CreateContext())
Expand All @@ -77,7 +77,7 @@ public virtual async Task From_sql_queryable_stored_procedure_composed()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'where [coh].ProductName.Contains(\"C\")'")]
public virtual async Task From_sql_queryable_stored_procedure_with_parameter_composed()
{
using (var context = CreateContext())
Expand All @@ -95,7 +95,7 @@ public virtual async Task From_sql_queryable_stored_procedure_with_parameter_com
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'orderby [mep].UnitPrice desc'")]
public virtual async Task From_sql_queryable_stored_procedure_take()
{
using (var context = CreateContext())
Expand All @@ -113,7 +113,7 @@ public virtual async Task From_sql_queryable_stored_procedure_take()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'Min()'")]
public virtual async Task From_sql_queryable_stored_procedure_min()
{
using (var context = CreateContext())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// 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 Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore.Query
{
public abstract class ComplexNavigationsQueryRelationalFixtureBase : ComplexNavigationsQueryFixtureBase
{
public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(
c => c
.Log(RelationalEventId.QueryClientEvaluationWarning));
}
}
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 Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel;
using Microsoft.EntityFrameworkCore.TestUtilities;
Expand Down Expand Up @@ -40,9 +39,5 @@ protected override void Configure(OwnedNavigationBuilder<Level3, Level4> l4)

l4.ToTable(nameof(Level1));
}

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(
c => c.Log(RelationalEventId.QueryClientEvaluationWarning));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public virtual void From_sql_queryable_stored_procedure_with_parameter()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'where [mep].TenMostExpensiveProducts.Contains(\"C\")'")]
public virtual void From_sql_queryable_stored_procedure_composed()
{
using (var context = CreateContext())
Expand All @@ -115,7 +115,7 @@ public virtual void From_sql_queryable_stored_procedure_composed()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'where [coh].ProductName.Contains(\"C\")'")]
public virtual void From_sql_queryable_stored_procedure_with_parameter_composed()
{
using (var context = CreateContext())
Expand All @@ -133,7 +133,7 @@ public virtual void From_sql_queryable_stored_procedure_with_parameter_composed(
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'orderby [mep].UnitPrice desc'")]
public virtual void From_sql_queryable_stored_procedure_take()
{
using (var context = CreateContext())
Expand All @@ -151,7 +151,7 @@ public virtual void From_sql_queryable_stored_procedure_take()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'Min()'")]
public virtual void From_sql_queryable_stored_procedure_min()
{
using (var context = CreateContext())
Expand Down Expand Up @@ -180,7 +180,7 @@ public virtual void From_sql_queryable_stored_procedure_with_include_throws()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'from MostExpensiveProduct b in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.MostExpensiveProduct])'")]
public virtual void From_sql_queryable_with_multiple_stored_procedures()
{
using (var context = CreateContext())
Expand All @@ -202,7 +202,7 @@ from b in context.Set<MostExpensiveProduct>()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'from Product p in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.Product])'")]
public virtual void From_sql_queryable_stored_procedure_and_select()
{
using (var context = CreateContext())
Expand All @@ -224,7 +224,7 @@ from p in context.Set<Product>()
}
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'from MostExpensiveProduct mep in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.MostExpensiveProduct])'")]
public virtual void From_sql_queryable_select_and_stored_procedure()
{
using (var context = CreateContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public abstract class GearsOfWarQueryRelationalFixture : GearsOfWarQueryFixtureB
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(
c => c
.Log(RelationalEventId.QueryClientEvaluationWarning)
.Log(RelationalEventId.ValueConversionSqlLiteralWarning));

protected override bool ShouldLogCategory(string logCategory)
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 Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestModels.Inheritance;
using Microsoft.EntityFrameworkCore.TestUtilities;

Expand Down Expand Up @@ -35,8 +34,5 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
modelBuilder.Entity<KiwiQuery>().HasDiscriminator().HasValue("Kiwi");
modelBuilder.Entity<EagleQuery>().HasDiscriminator().HasValue("Eagle");
}

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(c => c.Log(RelationalEventId.QueryClientEvaluationWarning));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public abstract class NorthwindQueryRelationalFixture<TModelCustomizer> : Northw
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(
c => c
.Log(RelationalEventId.QueryClientEvaluationWarning)
.Log(RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning)
.Log(RelationalEventId.QueryPossibleExceptionWithAggregateOperator)
.Log(RelationalEventId.ValueConversionSqlLiteralWarning))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
// 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 Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore.Query
{
public abstract class QueryFilterFuncletizationRelationalFixture : QueryFilterFuncletizationFixtureBase
{
public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
{
base.AddOptions(builder);
return builder.ConfigureWarnings(w => w.Ignore(RelationalEventId.QueryClientEvaluationWarning));
}
}
}
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 Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore.Query
Expand All @@ -17,9 +16,6 @@ protected RelationalOwnedQueryTestBase(TFixture fixture)
public abstract class RelationalOwnedQueryFixture : OwnedQueryFixtureBase
{
public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(c => c.Log(RelationalEventId.QueryClientEvaluationWarning));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query.Expressions;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Xunit;
Expand Down Expand Up @@ -247,12 +246,6 @@ public abstract class UdfFixtureBase : SharedStoreFixtureBase<DbContext>

public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
{
base.AddOptions(builder);
return builder.ConfigureWarnings(w => w.Ignore(RelationalEventId.QueryClientEvaluationWarning));
}

protected override bool ShouldLogCategory(string logCategory)
=> logCategory == DbLoggerCategory.Query.Name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public virtual void SaveChanges_can_be_used_with_no_transaction()
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().Last()).State = EntityState.Added;


// Issue #14935. Cannot eval 'Last()'
// Added AsEnumerable()
context.Entry(context.Set<TransactionCustomer>().AsEnumerable().Last()).State = EntityState.Added;

Assert.Throws<DbUpdateException>(() => context.SaveChanges());

Expand Down
29 changes: 23 additions & 6 deletions test/EFCore.Specification.Tests/BuiltInDataTypesTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,32 @@ public virtual void Can_perform_query_with_max_length()
{
Assert.NotNull(
context.Set<MaxLengthDataTypes>().Where(e => e.Id == 799 && e.String3 == shortString).ToList().SingleOrDefault());
Assert.NotNull(
context.Set<MaxLengthDataTypes>().Where(e => e.Id == 799 && e.ByteArray5.SequenceEqual(shortBinary)).ToList()
.SingleOrDefault());

Assert.NotNull(
context.Set<MaxLengthDataTypes>().Where(e => e.Id == 799 && e.String9000 == longString).ToList().SingleOrDefault());
Assert.NotNull(
context.Set<MaxLengthDataTypes>().Where(e => e.Id == 799 && e.ByteArray9000.SequenceEqual(longBinary)).ToList()
.SingleOrDefault());

if (context.Database.ProviderName == "Microsoft.EntityFrameworkCore.InMemory")
{
Assert.NotNull(
context.Set<MaxLengthDataTypes>().Where(e => e.Id == 799 && e.ByteArray5.SequenceEqual(shortBinary)).ToList()
.SingleOrDefault());

Assert.NotNull(
context.Set<MaxLengthDataTypes>().Where(e => e.Id == 799 && e.ByteArray9000.SequenceEqual(longBinary)).ToList()
.SingleOrDefault());
}
else
{
// Issue #14935. Cannot eval ''where [e].ByteArray5.SequenceEqual(__shortBinary_0)'
// Uses == operator instead.
Assert.NotNull(
context.Set<MaxLengthDataTypes>().Where(e => e.Id == 799 && e.ByteArray5 == shortBinary).ToList()
.SingleOrDefault());

Assert.NotNull(
context.Set<MaxLengthDataTypes>().Where(e => e.Id == 799 && e.ByteArray9000 == longBinary).ToList()
.SingleOrDefault());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public virtual Task First_logs_concurrent_access_async()
return ConcurrencyDetectorTest(c => c.Products.FirstAsync());
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'Last()'")]
public virtual Task Last_logs_concurrent_access_nonasync()
{
return ConcurrencyDetectorTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected class Email
public static implicit operator string(Email email) => email._value;
}

[Fact]
[Fact(Skip = "Issue #14935. Cannot eval 'where [e].Fuel.Equals(value(Microsoft.EntityFrameworkCore.CustomConvertersTestBase`1+Fuel[Microsoft.EntityFrameworkCore.CustomConvertersSqliteTest+CustomConvertersSqliteFixture]))'")]
public virtual void Can_query_and_update_with_conversion_for_custom_struct()
{
using (var context = CreateContext())
Expand Down
Loading

0 comments on commit e09c232

Please sign in to comment.