Skip to content

Commit

Permalink
Query API review changes
Browse files Browse the repository at this point in the history
Mostly moving types to different namespaces (internal or public), and a few renames.

Also, checked where Cosmos and other providers were using internal types and made those pubic.

Re-enabled API consistency, except for NotNull attributes (since these aren't breaking to add later.)

Fixes #12084
Fixes #15107
Fixes #15695
Fixes #15796
  • Loading branch information
ajcvickers committed Jul 23, 2019
1 parent 54c117d commit af70174
Show file tree
Hide file tree
Showing 359 changed files with 2,483 additions and 2,563 deletions.
16 changes: 8 additions & 8 deletions src/EFCore.Abstractions/DbFunctionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore
public class DbFunctionAttribute : Attribute
#pragma warning restore CA1813 // Avoid unsealed attributes
{
private string _functionName;
private string _name;
private string _schema;

/// <summary>
Expand All @@ -30,28 +30,28 @@ public DbFunctionAttribute()
/// <summary>
/// Initializes a new instance of the <see cref="DbFunctionAttribute" /> class.
/// </summary>
/// <param name="functionName">The name of the function in the database.</param>
/// <param name="name">The name of the function in the database.</param>
/// <param name="schema">The schema of the function in the database.</param>
public DbFunctionAttribute([NotNull] string functionName, [CanBeNull] string schema = null)
public DbFunctionAttribute([NotNull] string name, [CanBeNull] string schema = null)
{
Check.NotEmpty(functionName, nameof(functionName));
Check.NotEmpty(name, nameof(name));

_functionName = functionName;
_name = name;
_schema = schema;
}

/// <summary>
/// The name of the function in the database.
/// </summary>
public virtual string FunctionName
public virtual string Name
{
get => _functionName;
get => _name;
[param: NotNull]
set
{
Check.NotEmpty(value, nameof(value));

_functionName = value;
_name = value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// 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.Collections;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -37,13 +37,24 @@ public virtual void ProcessEntityTypeAdded(

var entityType = entityTypeBuilder.Metadata;
if (entityTypeBuilder.Metadata.BaseType == null
&& !entityTypeBuilder.Metadata.GetDerivedTypes().Any())
&& !Any(entityTypeBuilder.Metadata.GetDerivedTypes()))
{
entityTypeBuilder.HasDiscriminator(typeof(string))
.HasValue(entityType, entityType.ShortName());
}
}

private static bool Any([NotNull] IEnumerable source)
{
foreach (var _ in source)
{
return true;
}

return false;
}


/// <summary>
/// Called after the base type of an entity type changes.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/CaseExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public virtual SqlExpression Translate(IModel model, SqlExpression instance, Met
// arguments.Select(e => _sqlExpressionFactory.ApplyDefaultTypeMapping(e)).ToList())
// ?? _sqlExpressionFactory.Function(
// dbFunction.Schema,
// dbFunction.FunctionName,
// dbFunction.Name,
// arguments,
// method.ReturnType);
//}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.NavigationExpansion;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
Expand Down Expand Up @@ -312,7 +309,7 @@ protected override Expression VisitNew(NewExpression newExpression)
}
else
{
var projectionMember = _projectionMembers.Peek().AddMember(newExpression.Members[i]);
var projectionMember = _projectionMembers.Peek().Append(newExpression.Members[i]);
_projectionMembers.Push(projectionMember);
newArguments[i] = Visit(newExpression.Arguments[i]);
if (newArguments[i] == null)
Expand Down Expand Up @@ -350,7 +347,7 @@ protected override Expression VisitMemberInit(MemberInitExpression memberInitExp
}
else
{
var projectionMember = _projectionMembers.Peek().AddMember(memberAssignment.Member);
var projectionMember = _projectionMembers.Peek().Append(memberAssignment.Member);
_projectionMembers.Push(projectionMember);

var visitedExpression = Visit(memberAssignment.Expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Query;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Query.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.NavigationExpansion;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Storage;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -75,7 +71,7 @@ protected override Expression VisitShapedQueryExpression(ShapedQueryExpression s
shaperBody = new JObjectInjectingExpressionVisitor()
.Visit(shaperBody);
shaperBody = InjectEntityMaterializers(shaperBody);
shaperBody = new CosmosProjectionBindingRemovingExpressionVisitor(selectExpression, jObjectParameter, TrackQueryResults)
shaperBody = new CosmosProjectionBindingRemovingExpressionVisitor(selectExpression, jObjectParameter, IsTracking)
.Visit(shaperBody);

var shaperLambda = Expression.Lambda(
Expand All @@ -84,7 +80,7 @@ protected override Expression VisitShapedQueryExpression(ShapedQueryExpression s
jObjectParameter);

return Expression.New(
(Async
(IsAsync
? typeof(AsyncQueryingEnumerable<>)
: typeof(QueryingEnumerable<>)).MakeGenericType(shaperLambda.ReturnType).GetConstructors()[0],
Expression.Convert(QueryCompilationContext.QueryContextParameter, typeof(CosmosQueryContext)),
Expand Down Expand Up @@ -951,7 +947,7 @@ public override Expression Visit(Expression expression)
? _sqlExpressionFactory.In(
(SqlExpression)Visit(inExpression.Item),
_sqlExpressionFactory.Constant(inValues, typeMapping),
inExpression.Negated)
inExpression.IsNegated)
: null;

var nullCheckExpression = hasNullValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Pipeline;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.Expressions.Internal;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
using Microsoft.EntityFrameworkCore.Query;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.Expressions.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
{
Expand Down
16 changes: 8 additions & 8 deletions src/EFCore.Cosmos/Query/Internal/InExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
Expand All @@ -26,7 +26,7 @@ public InExpression(SqlExpression item, bool negated, SqlExpression values, Core
: base(typeof(bool), typeMapping)
{
Item = item;
Negated = negated;
IsNegated = negated;
Values = values;
}

Expand All @@ -44,7 +44,7 @@ public InExpression(SqlExpression item, bool negated, SqlExpression values, Core
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool Negated { get; }
public virtual bool IsNegated { get; }

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -74,7 +74,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual InExpression Negate() => new InExpression(Item, !Negated, Values, TypeMapping);
public virtual InExpression Negate() => new InExpression(Item, !IsNegated, Values, TypeMapping);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -84,7 +84,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// </summary>
public virtual InExpression Update(SqlExpression item, SqlExpression values)
=> item != Item || values != Values
? new InExpression(item, Negated, values, TypeMapping)
? new InExpression(item, IsNegated, values, TypeMapping)
: this;

/// <summary>
Expand All @@ -96,7 +96,7 @@ public virtual InExpression Update(SqlExpression item, SqlExpression values)
public override void Print(ExpressionPrinter expressionPrinter)
{
expressionPrinter.Visit(Item);
expressionPrinter.StringBuilder.Append(Negated ? " NOT IN " : " IN ");
expressionPrinter.StringBuilder.Append(IsNegated ? " NOT IN " : " IN ");
expressionPrinter.StringBuilder.Append("(");
expressionPrinter.Visit(Values);
expressionPrinter.StringBuilder.Append(")");
Expand All @@ -117,7 +117,7 @@ public override bool Equals(object obj)
private bool Equals(InExpression inExpression)
=> base.Equals(inExpression)
&& Item.Equals(inExpression.Item)
&& Negated.Equals(inExpression.Negated)
&& IsNegated.Equals(inExpression.IsNegated)
&& (Values == null ? inExpression.Values == null : Values.Equals(inExpression.Values));

/// <summary>
Expand All @@ -126,6 +126,6 @@ private bool Equals(InExpression inExpression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Item, Negated, Values);
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Item, IsNegated, Values);
}
}
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
{
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore.Cosmos/Query/Internal/ObjectAccessExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
using System;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.Expressions.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.Expressions.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
{
Expand Down
Loading

0 comments on commit af70174

Please sign in to comment.