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 8, 2019
1 parent 9be0341 commit 653cf66
Show file tree
Hide file tree
Showing 67 changed files with 796 additions and 551 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
66 changes: 53 additions & 13 deletions test/EFCore.Relational.Specification.Tests/TransactionTestBase.cs
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 Expand Up @@ -81,7 +85,10 @@ public virtual async Task SaveChangesAsync_can_be_used_with_no_transaction()
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().OrderBy(c => c.Id).Last()).State = EntityState.Added;

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

await Assert.ThrowsAsync<DbUpdateException>(() => context.SaveChangesAsync());

Expand Down Expand Up @@ -114,7 +121,10 @@ public virtual void SaveChanges_implicitly_starts_transaction()
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().OrderBy(c => c.Id).Last()).State = EntityState.Added;

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

Assert.Throws<DbUpdateException>(() => context.SaveChanges());
}
Expand All @@ -135,7 +145,10 @@ public virtual async Task SaveChangesAsync_implicitly_starts_transaction()
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().OrderBy(c => c.Id).Last()).State = EntityState.Added;

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

try
{
Expand Down Expand Up @@ -174,7 +187,10 @@ public virtual async Task SaveChanges_uses_enlisted_transaction(bool async, bool
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().Last()).State = EntityState.Added;

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

if (async)
{
Expand Down Expand Up @@ -221,7 +237,10 @@ public virtual async Task SaveChanges_uses_enlisted_transaction_after_connection
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().Last()).State = EntityState.Added;

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

context.Database.AutoTransactionsEnabled = true;
}
Expand Down Expand Up @@ -272,7 +291,10 @@ public virtual async Task SaveChanges_uses_enlisted_transaction_connectionString
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().Last()).State = EntityState.Added;

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

if (async)
{
Expand Down Expand Up @@ -329,7 +351,10 @@ public virtual async Task SaveChanges_uses_ambient_transaction(bool async, bool
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().Last()).State = EntityState.Added;

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

if (async)
{
Expand Down Expand Up @@ -387,7 +412,10 @@ public virtual async Task SaveChanges_uses_ambient_transaction_with_connectionSt
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().Last()).State = EntityState.Added;

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

if (async)
{
Expand Down Expand Up @@ -429,7 +457,10 @@ public virtual void SaveChanges_throws_for_suppressed_ambient_transactions(bool
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().Last()).State = EntityState.Added;

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

using (new TransactionScope(TransactionScopeOption.Suppress))
{
Expand Down Expand Up @@ -464,7 +495,10 @@ public virtual void SaveChanges_uses_enlisted_transaction_after_ambient_transact
Id = 77,
Name = "Bobble"
});
context.Entry(context.Set<TransactionCustomer>().Last()).State = EntityState.Added;

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

using (var transaction = new CommittableTransaction(TimeSpan.FromMinutes(10)))
Expand Down Expand Up @@ -670,7 +704,10 @@ public virtual void SaveChanges_uses_explicit_transaction_and_does_not_rollback_
{
var firstEntry = context.Entry(context.Set<TransactionCustomer>().OrderBy(c => c.Id).First());
firstEntry.State = EntityState.Deleted;
var lastEntry = context.Entry(context.Set<TransactionCustomer>().OrderBy(c => c.Id).Last());

// Issue #14935. Cannot eval 'Last()'
// Use AsEnumerable().
var lastEntry = context.Entry(context.Set<TransactionCustomer>().AsEnumerable().OrderBy(c => c.Id).Last());
lastEntry.State = EntityState.Added;

try
Expand Down Expand Up @@ -703,7 +740,10 @@ public virtual async Task SaveChangesAsync_uses_explicit_transaction_and_does_no
{
var firstEntry = context.Entry(context.Set<TransactionCustomer>().OrderBy(c => c.Id).First());
firstEntry.State = EntityState.Deleted;
var lastEntry = context.Entry(context.Set<TransactionCustomer>().OrderBy(c => c.Id).Last());

// Issue #14935. Cannot eval 'Last()'
// Use AsEnumerable().
var lastEntry = context.Entry(context.Set<TransactionCustomer>().OrderBy(c => c.Id).AsEnumerable().Last());
lastEntry.State = EntityState.Added;

try
Expand Down
Loading

0 comments on commit 653cf66

Please sign in to comment.