Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do extra processing for init-only fields #32342

Merged
merged 1 commit into from
Nov 20, 2023
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 @@ -2066,7 +2066,9 @@ protected override Expression VisitBinary(BinaryExpression node)
OrElse(
ReferenceEqual(currentVariable, Constant(null)),
ReferenceEqual(parameter, Constant(null))),
MakeBinary(node.NodeType, node.Left, parameter),
node is { NodeType: ExpressionType.Assign, Left: MemberExpression leftMemberExpression }
? leftMemberExpression.Assign(parameter)
: MakeBinary(node.NodeType, node.Left, parameter),
Call(
PopulateListMethod.MakeGenericMethod(property.ClrType.TryGetElementType(typeof(IEnumerable<>))!),
parameter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,70 @@ public abstract class JsonQueryAdHocTestBase : NonSharedModelTestBase
protected override string StoreName
=> "JsonQueryAdHocTest";

#region 32310

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Contains_on_nested_collection_with_init_only_navigation(bool async)
{
var contextFactory = await InitializeAsync<MyContext32310>(seed: Seed32310);
await using var context = contextFactory.CreateContext();

var query = context.Pubs
.Where(u => u.Visits.DaysVisited.Contains(new DateOnly(2023, 1, 1)));

var result = async
? await query.FirstOrDefaultAsync()!
: query.FirstOrDefault()!;

Assert.Equal("FBI", result.Name);
Assert.Equal(new DateOnly(2023, 1, 1), result.Visits.DaysVisited.Single());
}

protected virtual void Seed32310(MyContext32310 context)
{
var user = new Pub32310
{
Name = "FBI",
Visits = new Visits32310
{
LocationTag = "tag",
DaysVisited = new List<DateOnly> { new(2023, 1, 1) }
}
};

context.Add(user);
context.SaveChanges();
}

protected class MyContext32310 : DbContext
{
public MyContext32310(DbContextOptions options)
: base(options)
{
}

public DbSet<Pub32310> Pubs => Set<Pub32310>();

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Pub32310>(b => { b.OwnsOne(e => e.Visits).ToJson(); });
}

public class Pub32310
{
public int Id { get; set; }
public required string Name { get; set; }
public Visits32310 Visits { get; set; } = null!;
}

public class Visits32310
{
public string LocationTag { get; set; }
public required List<DateOnly> DaysVisited { get; init; }
}

#endregion

#region 29219

[ConditionalTheory]
Expand Down Expand Up @@ -893,7 +957,7 @@ public class MyJsonEntityLazyLoadingProxies
}

#endregion

#region NotICollection

[ConditionalTheory]
Expand Down
Loading