Esempio n. 1
0
 public virtual void LastOrDefault_without_order_by_issues_client_eval_warning()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(CoreStrings.WarningAsErrorTemplate(
                          $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                          RelationalStrings.ClientEvalWarning("LastOrDefault()")),
                      Assert.Throws <InvalidOperationException>(
                          () => context.Customers.LastOrDefault()).Message);
     }
 }
Esempio n. 2
0
 public virtual void Throws_when_warning_as_error()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(CoreStrings.WarningAsErrorTemplate(
                          $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                          RelationalStrings.ClientEvalWarning("[c].IsLondon")),
                      Assert.Throws <InvalidOperationException>(
                          () => context.Customers.Where(c => c.IsLondon).ToList()).Message);
     }
 }
Esempio n. 3
0
 public virtual void Last_with_order_by_issues_client_eval_warning_in_subquery()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(CoreStrings.WarningAsErrorTemplate(
                          $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                          RelationalStrings.ClientEvalWarning("Last()")),
                      Assert.Throws <InvalidOperationException>(
                          () => context.Customers.Where(c => c.CustomerID == "ALFKI" && c.Orders.OrderBy(o => o.OrderID).Last().OrderID > 1000).ToList()).Message);
     }
 }
        protected virtual void CheckClientEval([NotNull] object expression)
        {
            Check.NotNull(expression, nameof(expression));

            if (RelationalOptionsExtension.Extract(ContextOptions).IsQueryClientEvaluationEnabled == false)
            {
                throw new InvalidOperationException(RelationalStrings.ClientEvalDisabled(expression));
            }

            QueryCompilationContext.Logger.LogWarning(RelationalStrings.ClientEvalWarning(expression));
        }
Esempio n. 5
0
 public virtual void Throws_when_group_by()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(CoreStrings.WarningAsErrorTemplate(
                          $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                          RelationalStrings.ClientEvalWarning("GroupBy([c].CustomerID, [c])")),
                      Assert.Throws <InvalidOperationException>(
                          () => context.Customers
                          .GroupBy(c => c.CustomerID)
                          .ToList()).Message);
     }
 }
Esempio n. 6
0
 public virtual void Throws_when_orderby_multiple()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(CoreStrings.WarningAsErrorTemplate(
                          $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                          RelationalStrings.ClientEvalWarning("orderby [c].IsLondon asc, ClientMethod([c]) asc")),
                      Assert.Throws <InvalidOperationException>(
                          () => context.Customers
                          .OrderBy(c => c.IsLondon)
                          .ThenBy(c => ClientMethod(c))
                          .ToList()).Message);
     }
 }
Esempio n. 7
0
 public virtual void Throws_when_where_subquery_correlated()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(CoreStrings.WarningAsErrorTemplate(
                          $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                          RelationalStrings.ClientEvalWarning(
                              "{from Customer c2 in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.Specification.Tests.TestModels.Northwind.Customer]) where (([c1].CustomerID == [c2].CustomerID) AndAlso [c2].IsLondon) select [c2] => Any()}")),
                      Assert.Throws <InvalidOperationException>(
                          () => context.Customers
                          .Where(c1 => context.Customers
                                 .Any(c2 => c1.CustomerID == c2.CustomerID && c2.IsLondon))
                          .ToList()).Message);
     }
 }
Esempio n. 8
0
 public virtual void Throws_when_group_join()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(CoreStrings.WarningAsErrorTemplate(
                          $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                          RelationalStrings.ClientEvalWarning("join Int32 i in __p_0 on [e1].EmployeeID equals [i]")),
                      Assert.Throws <InvalidOperationException>(
                          () =>
                          (from e1 in context.Employees
                           join i in new[] { 1, 2, 3 } on e1.EmployeeID equals i into g
                           select e1)
                          .ToList()).Message);
     }
 }
Esempio n. 9
0
        protected virtual void CheckClientEval([NotNull] object expression)
        {
            Check.NotNull(expression, nameof(expression));

            var relationalOptionsExtension = RelationalOptionsExtension.Extract(ContextOptions);

            switch (relationalOptionsExtension.QueryClientEvaluationBehavior)
            {
            case QueryClientEvaluationBehavior.Throw:
                throw new InvalidOperationException(RelationalStrings.ClientEvalDisabled(expression));

            case QueryClientEvaluationBehavior.Warn:
                QueryCompilationContext.Logger.LogWarning(RelationalStrings.ClientEvalWarning(expression));
                break;
            }
        }
Esempio n. 10
0
 public virtual void Throws_when_select_many()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(
             CoreStrings.WarningAsErrorTemplate(
                 $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                 RelationalStrings.ClientEvalWarning("from Int32 i in value(System.Int32[])")),
             Assert.Throws <InvalidOperationException>(
                 () =>
                 (from c1 in context.Customers
                  from i in new[] { 1, 2, 3 }
                  select c1)
                 .ToList()).Message);
     }
 }
 public virtual void Throws_when_subquery_main_from_clause()
 {
     using (var context = CreateContext())
     {
         Assert.Equal(CoreStrings.WarningAsErrorTemplate(
                          $"{nameof(RelationalEventId)}.{nameof(RelationalEventId.QueryClientEvaluationWarning)}",
                          RelationalStrings.ClientEvalWarning("[c].IsLondon")),
                      Assert.Throws <InvalidOperationException>(
                          () =>
                          (from c1 in context.Customers
                           .Where(c => c.IsLondon)
                           .OrderBy(c => c.CustomerID)
                           .Take(5)
                           select c1)
                          .ToList()).Message);
     }
 }