Skip to content

Commit

Permalink
Merge branch 'rel/2.0.0-preview2' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
anpete committed Jun 5, 2017
2 parents 47630e9 + 150255f commit 3075c74
Show file tree
Hide file tree
Showing 36 changed files with 194 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@ public class BuildSource
BuildReference.ByName("mscorlib"),
BuildReference.ByName("netstandard", true),
BuildReference.ByName("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"),
BuildReference.ByName("System.Collections", true),
BuildReference.ByName("System.Collections.Concurrent", true),
BuildReference.ByName("System.ComponentModel", true),
BuildReference.ByName("System.ComponentModel.Annotations", true),
BuildReference.ByName("System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"),
BuildReference.ByName("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"),
BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"),
BuildReference.ByName("System.Data.Common", true),
BuildReference.ByName("System.Globalization", true),
BuildReference.ByName("System.Linq", true),
BuildReference.ByName("System.Reflection", true),
BuildReference.ByName("System.Reflection.Extensions", true),
BuildReference.ByName("System.Runtime", true),
BuildReference.ByName("System.Runtime.Extensions", true),
BuildReference.ByName("System.Threading", true),
BuildReference.ByName("System.Threading.Tasks", true),
BuildReference.ByName("System.ValueTuple", true)
#elif NETCOREAPP2_0
BuildReference.ByName("netstandard"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public virtual void Throws_when_where()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("[c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
Assert.Throws<InvalidOperationException>(
() => context.Customers.Where(c => c.IsLondon).ToList())
.Message);
Expand Down Expand Up @@ -69,7 +69,7 @@ public virtual void Throws_when_where_subquery_correlated()
Assert.Equal(CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage(
"{from Customer c2 in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.Customer]) where (([c1].CustomerID == [c2].CustomerID) AndAlso [c2].IsLondon) select [c2] => Any()}")),
"where {from Customer c2 in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.Customer]) where (([c1].CustomerID == [c2].CustomerID) AndAlso [c2].IsLondon) select [c2] => Any()}")),
Assert.Throws<InvalidOperationException>(
() => context.Customers
.Where(c1 => context.Customers
Expand Down Expand Up @@ -98,7 +98,7 @@ public virtual void Throws_when_from_sql_composed()
{
Assert.Equal(CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("[c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
Assert.Throws<InvalidOperationException>(
() => context.Customers
.FromSql(@"select * from ""Customers""")
Expand Down Expand Up @@ -128,7 +128,7 @@ public virtual void Throws_when_subquery_main_from_clause()
{
Assert.Equal(CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("[c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
Assert.Throws<InvalidOperationException>(
() =>
(from c1 in context.Customers
Expand Down Expand Up @@ -214,7 +214,7 @@ public virtual void Throws_when_first()
{
Assert.Equal(CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("[c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
Assert.Throws<InvalidOperationException>(
() => context.Customers.First(c => c.IsLondon)).Message);
}
Expand All @@ -227,7 +227,7 @@ public virtual void Throws_when_single()
{
Assert.Equal(CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("[c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
Assert.Throws<InvalidOperationException>(
() => context.Customers.Single(c => c.IsLondon)).Message);
}
Expand All @@ -240,7 +240,7 @@ public virtual void Throws_when_first_or_default()
{
Assert.Equal(CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("[c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
Assert.Throws<InvalidOperationException>(
() => context.Customers.FirstOrDefault(c => c.IsLondon)).Message);
}
Expand All @@ -253,7 +253,7 @@ public virtual void Throws_when_single_or_default()
{
Assert.Equal(CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("[c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
Assert.Throws<InvalidOperationException>(
() => context.Customers.SingleOrDefault(c => c.IsLondon)).Message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public virtual void Throws_when_warning_as_error()
{
Assert.Equal(CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("[c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
Assert.Throws<InvalidOperationException>(
() => context.Customers.Where(c => c.IsLondon).ToList()).Message);
}
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Diagnostics/RelationalEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private enum Id
/// This event is in the <see cref="DbLoggerCategory.Query" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="QueryModelExpressionEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// This event uses the <see cref="QueryModelClientEvalEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId QueryClientEvaluationWarning = MakeQueryId(Id.QueryClientEvaluationWarning);
Expand All @@ -426,7 +426,7 @@ private enum Id
/// This event is in the <see cref="DbLoggerCategory.Query" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="BinaryExpressionEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// This event uses the <see cref="ExpressionEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId QueryPossibleUnintendedUseOfEqualsWarning = MakeQueryId(Id.QueryPossibleUnintendedUseOfEqualsWarning);
Expand Down
31 changes: 13 additions & 18 deletions src/EFCore.Relational/Internal/RelationalLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -985,29 +985,29 @@ private static string MigrationsNotFound(EventDefinitionBase definition, EventDa
public static void QueryClientEvaluationWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Query> diagnostics,
[NotNull] QueryModel queryModel,
[NotNull] object expression)
[NotNull] object queryModelElement)
{
var definition = RelationalStrings.LogClientEvalWarning;

definition.Log(diagnostics, expression);
definition.Log(diagnostics, queryModelElement);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new QueryModelExpressionEventData(
new QueryModelClientEvalEventData(
definition,
QueryClientEvaluationWarning,
queryModel,
expression));
queryModelElement));
}
}

private static string QueryClientEvaluationWarning(EventDefinitionBase definition, EventData payload)
{
var d = (EventDefinition<object>)definition;
var p = (QueryModelExpressionEventData)payload;
return d.GenerateMessage(p.Expression);
var p = (QueryModelClientEvalEventData)payload;
return d.GenerateMessage(p.QueryModelElement);
}

/// <summary>
Expand All @@ -1016,33 +1016,28 @@ private static string QueryClientEvaluationWarning(EventDefinitionBase definitio
/// </summary>
public static void QueryPossibleUnintendedUseOfEqualsWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Query> diagnostics,
[NotNull] MethodCallExpression methodCallExpression,
[NotNull] Expression argument)
[NotNull] MethodCallExpression methodCallExpression)
{
var definition = RelationalStrings.LogPossibleUnintendedUseOfEquals;

definition.Log(
diagnostics,
methodCallExpression.Object,
argument);
definition.Log(diagnostics, methodCallExpression);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new BinaryExpressionEventData(
new ExpressionEventData(
definition,
QueryPossibleUnintendedUseOfEqualsWarning,
methodCallExpression.Object,
argument));
methodCallExpression));
}
}

private static string QueryPossibleUnintendedUseOfEqualsWarning(EventDefinitionBase definition, EventData payload)
{
var d = (EventDefinition<object, object>)definition;
var p = (BinaryExpressionEventData)payload;
return d.GenerateMessage(p.Left, p.Right);
var d = (EventDefinition<object>)definition;
var p = (ExpressionEventData)payload;
return d.GenerateMessage(p.Expression);
}

/// <summary>
Expand Down

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

2 changes: 1 addition & 1 deletion src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
<comment>Warning RelationalEventId.AmbientTransactionWarning</comment>
</data>
<data name="LogPossibleUnintendedUseOfEquals" xml:space="preserve">
<value>Possible unintended use of method Equals(object) for arguments of different types: '{left}', '{right}'. This comparison will always return 'false'.</value>
<value>Possible unintended use of method Equals(object) for arguments of different types in expression '{expression}'. This comparison will always return 'false'.</value>
<comment>Warning RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning object object</comment>
</data>
<data name="StoredProcedureIncludeNotSupported" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public virtual Expression Translate(MethodCallExpression methodCallExpression)
Expression.Convert(argument, unwrappedArgumentType));
}

_logger.QueryPossibleUnintendedUseOfEqualsWarning(methodCallExpression, argument);
_logger.QueryPossibleUnintendedUseOfEqualsWarning(methodCallExpression);

// Equals(object) always returns false if when comparing objects of different types
return Expression.Constant(false);
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore.Relational/Query/RelationalQueryModelVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ var sqlTranslatingExpressionVisitor

if (RequiresClientFilter)
{
WarnClientEval(queryModel, whereClause.Predicate);
WarnClientEval(queryModel, whereClause);

base.VisitWhereClause(whereClause, queryModel, index);
}
Expand Down Expand Up @@ -1162,14 +1162,14 @@ var typeIsExpressionTranslatingVisitor
/// Generated a client-eval warning
/// </summary>
/// <param name="queryModel"> The query model </param>
/// <param name="expression"> The expression being client-eval'd. </param>
/// <param name="queryModelElement"> The expression being client-eval'd. </param>
protected virtual void WarnClientEval(
[NotNull] QueryModel queryModel,
[NotNull] object expression)
[NotNull] object queryModelElement)
{
Check.NotNull(expression, nameof(expression));
Check.NotNull(queryModelElement, nameof(queryModelElement));

QueryCompilationContext.Logger.QueryClientEvaluationWarning(queryModel, expression);
QueryCompilationContext.Logger.QueryClientEvaluationWarning(queryModel, queryModelElement);
}

private class TypeIsExpressionTranslatingVisitor : ExpressionVisitorBase
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/Internal/KeyPropagator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public virtual async Task PropagateValueAsync(
}
}

private bool TryPropagateValue(InternalEntityEntry entry, IProperty property)
private static bool TryPropagateValue(InternalEntityEntry entry, IProperty property)
{
var entityType = entry.EntityType;
var stateManager = entry.StateManager;
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/ChangeTracking/Internal/ValueGenerationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ await valueGenerator.NextAsync(entityEntry, cancellationToken),
}
}

private IEnumerable<IProperty> FindPropagatingProperties(InternalEntityEntry entry)
private static IEnumerable<IProperty> FindPropagatingProperties(InternalEntityEntry entry)
=> entry.EntityType.GetProperties().Where(
property => property.IsForeignKey()
&& property.ClrType.IsDefaultValue(entry[property]));

private IEnumerable<IProperty> FindGeneratingProperties(InternalEntityEntry entry)
private static IEnumerable<IProperty> FindGeneratingProperties(InternalEntityEntry entry)
=> entry.EntityType.GetProperties().Where(
property => property.RequiresValueGenerator()
&& property.ClrType.IsDefaultValue(entry[property]));
Expand Down
37 changes: 37 additions & 0 deletions src/EFCore/Diagnostics/ExpressionEventData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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 System;
using System.Diagnostics;
using System.Linq.Expressions;
using JetBrains.Annotations;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
/// <summary>
/// A <see cref="DiagnosticSource" /> event payload class for events that have
/// a query expression.
/// </summary>
public class ExpressionEventData : EventData
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="eventDefinition"> The event definition. </param>
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
/// <param name="expression"> The <see cref="Expression" />. </param>
public ExpressionEventData(
[NotNull] EventDefinitionBase eventDefinition,
[NotNull] Func<EventDefinitionBase, EventData, string> messageGenerator,
[NotNull] Expression expression)
: base(eventDefinition, messageGenerator)
{
Expression = expression;
}

/// <summary>
/// The left <see cref="Expression" />.
/// </summary>
public virtual Expression Expression { get; }
}
}
11 changes: 6 additions & 5 deletions src/EFCore/Diagnostics/IncludeEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Query.ResultOperators.Internal;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
Expand All @@ -18,19 +19,19 @@ public class IncludeEventData : EventData
/// </summary>
/// <param name="eventDefinition"> The event definition. </param>
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
/// <param name="includeSpecification"> The Include specification. </param>
/// <param name="includeResultOperator"> The <see cref="IncludeResultOperator"/>. </param>
public IncludeEventData(
[NotNull] EventDefinitionBase eventDefinition,
[NotNull] Func<EventDefinitionBase, EventData, string> messageGenerator,
[NotNull] string includeSpecification)
[NotNull] IncludeResultOperator includeResultOperator)
: base(eventDefinition, messageGenerator)
{
IncludeSpecification = includeSpecification;
IncludeResultOperator = includeResultOperator;
}

/// <summary>
/// The <see cref="EntityFrameworkQueryableExtensions.Include{TEntity,TProperty}" /> specification.
/// The <see cref="EntityFrameworkQueryableExtensions.Include{TEntity,TProperty}" /> result operator.
/// </summary>
public virtual string IncludeSpecification { get; }
public virtual IncludeResultOperator IncludeResultOperator { get; }
}
}
Loading

0 comments on commit 3075c74

Please sign in to comment.