Skip to content

Commit

Permalink
More API review changes
Browse files Browse the repository at this point in the history
* Remove indexMap parameter of `IEntityMaterializerSource.CreateMaterializeExpression()`
* Move `IsEFPropertyMethod` to `MethodInfoExtensions`
* Rename `MemberIdentity` file
* Made members private on `ExpressionPrinter`
* Use `IReadOnlyList` instead of `IList` where appropriate
* Added factory methods to `SqlFunctionExpression`
* Seal `public override ExpressionType NodeType => ExpressionType.Extension;`
* Added dependency object for QueryCompilationContext

Part of #15662
  • Loading branch information
ajcvickers committed Jul 23, 2019
1 parent af70174 commit 83349fe
Show file tree
Hide file tree
Showing 90 changed files with 438 additions and 192 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ContainsTranslator(ISqlExpressionFactory sqlExpressionFactory)
/// 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 SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
if (method.IsGenericMethod
&& method.GetGenericMethodDefinition().Equals(_containsMethod))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CosmosMethodCallTranslatorProvider(
/// 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 SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
// TODO: UDF support. See issue#15338
//var dbFunction = model.FindDbFunction(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public EntityProjectionExpression(IEntityType entityType, Expression accessExpre
/// 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 ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public EqualsTranslator(ISqlExpressionFactory sqlExpressionFactory)
/// 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 SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
SqlExpression left = null;
SqlExpression right = null;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface IMethodCallTranslator
/// 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>
SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments);
SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public interface IMethodCallTranslatorProvider
/// 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>
SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments);
SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ObjectArrayProjectionExpression(
/// 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 ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/OrderingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public OrderingExpression(SqlExpression expression, bool ascending)
/// 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 ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/ProjectionExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public virtual string Name
/// 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 ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public RootReferenceExpression(IEntityType entityType, string alias)
/// 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 ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/SelectExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public virtual void ReverseOrderings()
/// 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 ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public EntityProjectionExpression(

public virtual IEntityType EntityType { get; }
public override Type Type => EntityType.ClrType;
public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

public virtual Expression BindProperty(IProperty property)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public virtual void ApplyServerProjection()
public virtual Expression ServerQueryExpression { get; set; }
public virtual ParameterExpression ValueBufferParameter { get; }
public override Type Type => typeof(IEnumerable<ValueBuffer>);
public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

private Expression CreateReadValueExpression(
Type type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public InMemoryTableExpression(IEntityType entityType)

public virtual IEntityType EntityType { get; }

public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

protected override Expression VisitChildren(ExpressionVisitor visitor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public virtual void Print(ExpressionPrinter expressionPrinter)

public override Type Type { get; }

public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

public virtual int CollectionId { get; }
public virtual Expression Parent { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public virtual void Print(ExpressionPrinter expressionPrinter)

public override Type Type { get; }

public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;
public virtual RelationalCollectionShaperExpression Parent { get; }
public virtual bool IsInclude { get; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Query/EntityProjectionExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public virtual EntityProjectionExpression UpdateEntityType(IEntityType derivedTy
}

public virtual IEntityType EntityType { get; }
public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;
public override Type Type => EntityType.ClrType;

public virtual ColumnExpression BindProperty(IProperty property)
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Query/IMethodCallTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace Microsoft.EntityFrameworkCore.Query
{
public interface IMethodCallTranslator
{
SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments);
SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace Microsoft.EntityFrameworkCore.Query
{
public interface IMethodCallTranslatorProvider
{
SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments);
SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ComparisonTranslator(ISqlExpressionFactory sqlExpressionFactory)
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
if (method.ReturnType == typeof(int))
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Query/Internal/ContainsTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ContainsTranslator(ISqlExpressionFactory sqlExpressionFactory)
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
if (method.IsGenericMethod
&& method.GetGenericMethodDefinition().Equals(_containsMethod))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public EnumHasFlagTranslator(ISqlExpressionFactory sqlExpressionFactory)
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
if (Equals(method, _methodInfo))
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Query/Internal/EqualsTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public EqualsTranslator(ISqlExpressionFactory sqlExpressionFactory)
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
SqlExpression left = null;
SqlExpression right = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GetValueOrDefaultTranslator(ISqlExpressionFactory sqlExpressionFactory)
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
if (method.Name == nameof(Nullable<int>.GetValueOrDefault)
&& method.ReturnType.IsNumeric())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public StringMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
if (Equals(method, _isNullOrEmptyMethodInfo))
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Query/Internal/LikeTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public LikeTranslator(ISqlExpressionFactory sqlExpressionFactory)
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
if (Equals(method, _methodInfo))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RelationalCollectionShaperExpression(
public virtual Type ElementType { get; }

public override Type Type => Navigation?.ClrType ?? typeof(List<>).MakeGenericType(ElementType);
public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

protected override Expression VisitChildren(ExpressionVisitor visitor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public RelationalMethodCallTranslatorProvider([NotNull] RelationalMethodCallTran
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IList<SqlExpression> arguments)
public virtual SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
var dbFunction = model.FindDbFunction(method);
if (dbFunction != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ private SqlBinaryExpression CreateJoinPredicate(
}

private SqlBinaryExpression CreateJoinPredicate(
IList<Expression> outerExpressions,
IList<Expression> innerExpressions)
IReadOnlyList<Expression> outerExpressions,
IReadOnlyList<Expression> innerExpressions)
{
SqlBinaryExpression result = null;
for (var i = 0; i < outerExpressions.Count; i++)
Expand Down
12 changes: 6 additions & 6 deletions src/EFCore.Relational/Query/SqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public virtual SqlFunctionExpression Function(
typeMappedArguments.Add(ApplyDefaultTypeMapping(argument));
}

return new SqlFunctionExpression(
return SqlFunctionExpression.Create(
name,
typeMappedArguments,
returnType,
Expand All @@ -335,7 +335,7 @@ public virtual SqlFunctionExpression Function(
typeMappedArguments.Add(ApplyDefaultTypeMapping(argument));
}

return new SqlFunctionExpression(
return SqlFunctionExpression.Create(
schema,
name,
typeMappedArguments,
Expand All @@ -353,7 +353,7 @@ public virtual SqlFunctionExpression Function(
typeMappedArguments.Add(ApplyDefaultTypeMapping(argument));
}

return new SqlFunctionExpression(
return SqlFunctionExpression.Create(
instance,
name,
typeMappedArguments,
Expand All @@ -362,13 +362,13 @@ public virtual SqlFunctionExpression Function(
}

public virtual SqlFunctionExpression Function(string name, Type returnType, RelationalTypeMapping typeMapping = null)
=> new SqlFunctionExpression(name, returnType, typeMapping);
=> SqlFunctionExpression.CreateNiladic(name, returnType, typeMapping);

public virtual SqlFunctionExpression Function(string schema, string name, Type returnType, RelationalTypeMapping typeMapping = null)
=> new SqlFunctionExpression(schema, name, returnType, typeMapping);
=> SqlFunctionExpression.CreateNiladic(schema, name, returnType, typeMapping);

public virtual SqlFunctionExpression Function(SqlExpression instance, string name, Type returnType, RelationalTypeMapping typeMapping = null)
=> new SqlFunctionExpression(ApplyDefaultTypeMapping(instance), name, returnType, typeMapping);
=> SqlFunctionExpression.CreateNiladic(ApplyDefaultTypeMapping(instance), name, returnType, typeMapping);

public virtual ExistsExpression Exists(SelectExpression subquery, bool negated)
=> new ExistsExpression(subquery, negated, _boolTypeMapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public OrderingExpression(SqlExpression expression, bool ascending)
public virtual SqlExpression Expression { get; }
public virtual bool IsAscending { get; }

public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;
public override Type Type => Expression.Type;
protected override Expression VisitChildren(ExpressionVisitor visitor)
=> Update((SqlExpression)visitor.Visit(Expression));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ProjectionExpression(SqlExpression expression, string alias)
public virtual SqlExpression Expression { get; }

public override Type Type => Expression.Type;
public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;

protected override Expression VisitChildren(ExpressionVisitor visitor)
=> Update((SqlExpression)visitor.Visit(Expression));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ public void ApplyPredicate(SqlExpression expression)
}
}

public override ExpressionType NodeType => ExpressionType.Extension;

public Expression ApplyGrouping(Expression keySelector)
{
ClearOrdering();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected SqlExpression(Type type, RelationalTypeMapping typeMapping)
protected override Expression VisitChildren(ExpressionVisitor visitor)
=> throw new InvalidOperationException("VisitChildren must be overridden in class deriving from SqlExpression");

public override ExpressionType NodeType => ExpressionType.Extension;
public sealed override ExpressionType NodeType => ExpressionType.Extension;
public abstract void Print(ExpressionPrinter expressionPrinter);

public override bool Equals(object obj)
Expand Down
Loading

0 comments on commit 83349fe

Please sign in to comment.