Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,17 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio

if (expression is MethodCallExpression methodCallExpression)
{
if (methodCallExpression.Method.IsGenericMethod
&& methodCallExpression.Method.DeclaringType == typeof(Enumerable)
&& methodCallExpression.Method.Name == nameof(Enumerable.ToList)
&& methodCallExpression.Arguments.Count == 1
&& methodCallExpression.Arguments[0].Type.TryGetElementType(typeof(IQueryable<>)) != null)
if (methodCallExpression is
{
Method.IsGenericMethod: true,
Method.Name: nameof(Enumerable.ToList),
Method: var method,
Arguments: [var argument]
}
&& method.DeclaringType == typeof(Enumerable)
&& argument.Type.TryGetElementType(typeof(IQueryable<>)) != null)
{
var subquery = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(
methodCallExpression.Arguments[0]);
if (subquery != null)
if (_queryableMethodTranslatingExpressionVisitor.TranslateSubquery(argument) is ShapedQueryExpression subquery)
{
_clientProjections!.Add(subquery);
// expression.Type here will be List<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// </summary>
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public virtual CrossApplyExpression Update(TableExpressionBase table)
public override CrossApplyExpression Update(TableExpressionBase table)
=> table != Table
? new CrossApplyExpression(table, GetAnnotations())
: this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// </summary>
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public virtual CrossJoinExpression Update(TableExpressionBase table)
public override CrossJoinExpression Update(TableExpressionBase table)
=> table != Table
? new CrossJoinExpression(table, GetAnnotations())
: this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <param name="joinPredicate">The <see cref="PredicateJoinExpressionBase.JoinPredicate" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public virtual InnerJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate)
public override InnerJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate)
=> table != Table || joinPredicate != JoinPredicate
? new InnerJoinExpression(table, joinPredicate, GetAnnotations())
: this;

/// <summary>
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
/// return this expression.
/// </summary>
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public override InnerJoinExpression Update(TableExpressionBase table)
=> table != Table
? new InnerJoinExpression(table, JoinPredicate, GetAnnotations())
: this;

/// <inheritdoc />
protected override TableExpressionBase CreateWithAnnotations(IEnumerable<IAnnotation> annotations)
=> new InnerJoinExpression(Table, JoinPredicate, annotations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ protected JoinExpressionBase(TableExpressionBase table, IEnumerable<IAnnotation>
/// </summary>
public virtual TableExpressionBase Table { get; }

/// <summary>
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
/// return this expression.
/// </summary>
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public abstract JoinExpressionBase Update(TableExpressionBase table);

/// <inheritdoc />
public override bool Equals(object? obj)
=> obj != null
Expand Down
13 changes: 12 additions & 1 deletion src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <param name="joinPredicate">The <see cref="PredicateJoinExpressionBase.JoinPredicate" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public virtual LeftJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate)
public override LeftJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate)
=> table != Table || joinPredicate != JoinPredicate
? new LeftJoinExpression(table, joinPredicate, GetAnnotations())
: this;

/// <summary>
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
/// return this expression.
/// </summary>
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public override LeftJoinExpression Update(TableExpressionBase table)
=> table != Table
? new LeftJoinExpression(table, JoinPredicate, GetAnnotations())
: this;

/// <inheritdoc />
protected override TableExpressionBase CreateWithAnnotations(IEnumerable<IAnnotation> annotations)
=> new LeftJoinExpression(Table, JoinPredicate, annotations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// </summary>
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public virtual OuterApplyExpression Update(TableExpressionBase table)
public override OuterApplyExpression Update(TableExpressionBase table)
=> table != Table
? new OuterApplyExpression(table, GetAnnotations())
: this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ protected PredicateJoinExpressionBase(
/// </summary>
public virtual SqlExpression JoinPredicate { get; }

/// <summary>
/// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will
/// return this expression.
/// </summary>
/// <param name="table">The <see cref="JoinExpressionBase.Table" /> property of the result.</param>
/// <param name="joinPredicate">The <see cref="PredicateJoinExpressionBase.JoinPredicate" /> property of the result.</param>
/// <returns>This expression if no children changed, or an expression with the updated children.</returns>
public abstract PredicateJoinExpressionBase Update(TableExpressionBase table, SqlExpression joinPredicate);

/// <inheritdoc />
public override bool Equals(object? obj)
=> obj != null
Expand Down
15 changes: 9 additions & 6 deletions src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,12 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
Type? providerType,
CoreTypeMapping? elementMapping)
{
var elementType = modelType.TryGetElementType(typeof(IEnumerable<>))!;
if (TryFindJsonCollectionMapping(
info.CoreTypeMappingInfo, modelType, providerType, ref elementMapping, out var collectionReaderWriter))
{
var elementType = modelType.TryGetElementType(typeof(IEnumerable<>))!;

return TryFindJsonCollectionMapping(
info.CoreTypeMappingInfo, modelType, providerType, ref elementMapping, out var collectionReaderWriter)
? (RelationalTypeMapping)FindMapping(
return (RelationalTypeMapping)FindMapping(
info.WithConverter(
// Note that the converter info is only used temporarily here and never creates an instance.
new ValueConverterInfo(modelType, typeof(string), _ => null!)))!
Expand All @@ -242,8 +243,10 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
: typeof(ListComparer<>).MakeGenericType(elementMapping!.Comparer.Type),
elementMapping!.Comparer),
elementMapping,
collectionReaderWriter)
: null;
collectionReaderWriter);
}

return null;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@ public virtual Expression Process(Expression expression)

table = table switch
{
InnerJoinExpression ij => ij.Update(newOpenJsonExpression, ij.JoinPredicate),
LeftJoinExpression lj => lj.Update(newOpenJsonExpression, lj.JoinPredicate),
CrossJoinExpression cj => cj.Update(newOpenJsonExpression),
CrossApplyExpression ca => ca.Update(newOpenJsonExpression),
OuterApplyExpression oa => oa.Update(newOpenJsonExpression),
_ => newOpenJsonExpression,
JoinExpressionBase j => j.Update(newOpenJsonExpression),
SqlServerOpenJsonExpression => newOpenJsonExpression,
_ => throw new UnreachableException()
};

foreach (var columnInfo in openJsonExpression.ColumnInfos!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ static SqlServerTypeMappingSource()
/// </summary>
public SqlServerTypeMappingSource(
TypeMappingSourceDependencies dependencies,
RelationalTypeMappingSourceDependencies relationalDependencies,
ISqlServerSingletonOptions sqlServerSingletonOptions)
RelationalTypeMappingSourceDependencies relationalDependencies)
: base(dependencies, relationalDependencies)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/ListComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static int GetHashCode(IEnumerable<TElement> source, ValueComparer<TElem

private static IList<TElement> Snapshot(IEnumerable<TElement> source, ValueComparer<TElement> elementComparer)
{
if (!(source is IList<TElement> sourceList))
if (source is not IList<TElement> sourceList)
{
throw new InvalidOperationException(
CoreStrings.BadListType(
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/NullableValueTypeListComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static int GetHashCode(IEnumerable<TElement?> source, ValueComparer<TEle

private static IList<TElement?> Snapshot(IEnumerable<TElement?> source, ValueComparer<TElement> elementComparer)
{
if (!(source is IList<TElement?> sourceList))
if (source is not IList<TElement?> sourceList)
{
throw new InvalidOperationException(
CoreStrings.BadListType(
Expand Down
3 changes: 1 addition & 2 deletions test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,7 @@ private static SqlServerTypeMappingSource CreateTypeMappingSource(
params IRelationalTypeMappingSourcePlugin[] plugins)
=> new(
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
new RelationalTypeMappingSourceDependencies(plugins),
new SqlServerSingletonOptions());
new RelationalTypeMappingSourceDependencies(plugins));

private class TestTypeMappingPlugin<T> : IRelationalTypeMappingSourcePlugin
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public void Generate_separates_operations_by_a_blank_line()
new CSharpHelper(
new SqlServerTypeMappingSource(
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>(),
new SqlServerSingletonOptions()))));
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>()))));

var builder = new IndentedStringBuilder();

Expand Down Expand Up @@ -3160,8 +3159,7 @@ private void Test<T>(T operation, string expectedCode, Action<T> assert)
new IRelationalTypeMappingSourcePlugin[]
{
new SqlServerNetTopologySuiteTypeMappingSourcePlugin(NtsGeometryServices.Instance)
}),
new SqlServerSingletonOptions()))));
})))));

var builder = new IndentedStringBuilder();
generator.Generate("mb", new[] { operation }, builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ private static void MissingAnnotationCheck(
{
var sqlServerTypeMappingSource = new SqlServerTypeMappingSource(
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>(),
new SqlServerSingletonOptions());
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>());

var sqlServerAnnotationCodeGenerator = new SqlServerAnnotationCodeGenerator(
new AnnotationCodeGeneratorDependencies(sqlServerTypeMappingSource));
Expand Down Expand Up @@ -452,8 +451,7 @@ public void Snapshot_with_enum_discriminator_uses_converted_values()
{
var sqlServerTypeMappingSource = new SqlServerTypeMappingSource(
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>(),
new SqlServerSingletonOptions());
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>());

var codeHelper = new CSharpHelper(
sqlServerTypeMappingSource);
Expand Down Expand Up @@ -510,8 +508,7 @@ private static void AssertConverter(ValueConverter valueConverter, string expect

var sqlServerTypeMappingSource = new SqlServerTypeMappingSource(
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>(),
new SqlServerSingletonOptions());
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>());

var codeHelper = new CSharpHelper(sqlServerTypeMappingSource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ private IMigrationsScaffolder CreateMigrationScaffolder<TContext>()
var idGenerator = new MigrationsIdGenerator();
var sqlServerTypeMappingSource = new SqlServerTypeMappingSource(
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>(),
new SqlServerSingletonOptions());
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>());
var sqlServerAnnotationCodeGenerator = new SqlServerAnnotationCodeGenerator(
new AnnotationCodeGeneratorDependencies(sqlServerTypeMappingSource));
var code = new CSharpHelper(sqlServerTypeMappingSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7769,8 +7769,7 @@ protected CSharpMigrationsGenerator CreateMigrationsGenerator()
new IRelationalTypeMappingSourcePlugin[]
{
new SqlServerNetTopologySuiteTypeMappingSourcePlugin(NtsGeometryServices.Instance)
}),
new SqlServerSingletonOptions());
}));

var codeHelper = new CSharpHelper(sqlServerTypeMappingSource);

Expand Down
3 changes: 1 addition & 2 deletions test/EFCore.Design.Tests/Query/LinqToCSharpTranslatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,8 +1835,7 @@ private void AssertCore(Expression expression, bool isStatement, string expected
{
var typeMappingSource = new SqlServerTypeMappingSource(
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
new RelationalTypeMappingSourceDependencies(new IRelationalTypeMappingSourcePlugin[0]),
new SqlServerSingletonOptions());
new RelationalTypeMappingSourceDependencies(new IRelationalTypeMappingSourcePlugin[0]));

var translator = new CSharpHelper(typeMappingSource);
var namespaces = new HashSet<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,5 @@ private static ScaffoldingTypeMapper CreateMapper()
=> new(
new SqlServerTypeMappingSource(
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>(),
new SqlServerSingletonOptions()));
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>()));
}
Loading