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 @@ -1976,9 +1976,8 @@ protected override Expression VisitBinary(BinaryExpression node)
var currentVariable = Variable(parameter!.Type);
return Block(
new[] { currentVariable },
Assign(
currentVariable,
MakeMemberAccess(_instance, property.GetMemberInfo(forMaterialization: true, forSet: false))),
MakeMemberAccess(_instance, property.GetMemberInfo(forMaterialization: true, forSet: false))
.Assign(currentVariable),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the order reversed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. The second call to Assign is to an extension method.

IfThenElse(
OrElse(
ReferenceEqual(currentVariable, Constant(null)),
Expand All @@ -1991,7 +1990,11 @@ protected override Expression VisitBinary(BinaryExpression node)
));
}

return MakeBinary(node.NodeType, Visit(node.Left), parameter!);
var visitedLeft = Visit(node.Left);
return node.NodeType == ExpressionType.Assign
&& visitedLeft is MemberExpression memberExpression
? memberExpression.Assign(parameter!)
: MakeBinary(node.NodeType, visitedLeft, parameter!);
}

return base.VisitBinary(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
{
modelBuilder.Entity<JsonEntityBasic>().Property(x => x.Id).ValueGeneratedNever();
modelBuilder.Entity<EntityBasic>().Property(x => x.Id).ValueGeneratedNever();
modelBuilder.Entity<JsonEntityBasicForReference>().Property(x => x.Id).ValueGeneratedNever();
modelBuilder.Entity<JsonEntityBasicForReference>(
b =>
{
b.Property(x => x.Id).ValueGeneratedNever();
b.Property(x => x.Name);
});

modelBuilder.Entity<JsonEntityBasicForCollection>().Property(x => x.Id).ValueGeneratedNever();
modelBuilder.Entity<JsonEntityBasic>().OwnsOne(
x => x.OwnedReferenceRoot, b =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class JsonEntityAllTypes
private Collection<JsonEnum?> _testNullableEnumWithIntConverterCollectionX = new() { JsonEnum.Three };

public int Id { get; set; }
public JsonOwnedAllTypes Reference { get; set; }
public List<JsonOwnedAllTypes> Collection { get; set; }
public JsonOwnedAllTypes Reference { get; init; }
public List<JsonOwnedAllTypes> Collection { get; init; }

public string[] TestDefaultStringCollection { get; set; }
public List<string> TestMaxLengthStringCollection { get; set; }
public string[] TestDefaultStringCollection { get; init; }
public List<string> TestMaxLengthStringCollection { get; init; }
public IList<short> TestInt16Collection { get; set; }

public int[] TestInt32Collection { get; set; } = Array.Empty<int>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Microsoft.EntityFrameworkCore.TestModels.JsonQuery;

public class JsonEntityBasicForCollection
{
public int Id { get; set; }
public string Name { get; set; }
public int Id { get; init; }
public string Name { get; init; }

public int? ParentId { get; set; }
public JsonEntityBasic Parent { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ namespace Microsoft.EntityFrameworkCore.TestModels.JsonQuery;

public class JsonEntityBasicForReference
{
public int Id { get; set; }
public string Name { get; set; }
private int _id;
private string _name;

public int Id
=> _id;

public string Name
=> _name;

public int? ParentId { get; set; }
public JsonEntityBasic Parent { get; set; }

public void SetIdAndName(int id, string name)
{
_id = id;
_name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class JsonOwnedBranch
public decimal Fraction { get; set; }

public JsonEnum Enum { get; set; }
public JsonEnum? NullableEnum { get; set; }
public JsonEnum[] Enums { get; set; }
public JsonEnum?[] NullableEnums { get; set; }
public JsonEnum? NullableEnum { get; init; }
public JsonEnum[] Enums { get; init; }
public JsonEnum?[] NullableEnums { get; init; }

public JsonOwnedLeaf OwnedReferenceLeaf { get; set; }
public List<JsonOwnedLeaf> OwnedCollectionLeaf { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ public static IReadOnlyList<EntityBasic> CreateEntitiesBasic()

public static IReadOnlyList<JsonEntityBasicForReference> CreateJsonEntitiesBasicForReference()
{
var entity1 = new JsonEntityBasicForReference { Id = 1, Name = "EntityReference1" };
var entity1 = new JsonEntityBasicForReference();
entity1.SetIdAndName(1, "EntityReference1");

return new List<JsonEntityBasicForReference> { entity1 };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
x => x == true ? "Y" : "N"));
});

modelBuilder.Entity<JsonEntityBasicForReference>(
b =>
{
b.Property(x => x.Id);
b.Property(x => x.Name);
});

base.OnModelCreating(modelBuilder, context);
}

Expand Down