Closed
Description
Using EF Core 7.0.0-rc.2.22472.11 (also same in v7.0.0-rtm.22504.12)
When JSon child object has a column named Id (f.ex of type Int) the materialization will throw:
System.ArgumentException: 'Expression of type 'System.Object' cannot be used for constructor parameter of type 'System.Int32'
Make these modifications to NewInEFCore7 sample in EntityFramework.Docs to reproduce the bug:
public class Commit
{
public Commit(int id, DateTime committedOn, string comment)
{
Id = id;
CommittedOn = committedOn;
Comment = comment;
}
public int Id {get; private set; }
public DateTime CommittedOn { get; private set; }
public string Comment { get; set; }
}
// Update BuildPostMetadata method to send in an id as constructor parameter
for (var j = 0; j < random.Next(3); j++)
{
update.Commits.Add(new(j+1, DateTime.Today, $"Commit #{j + 1}"));
}
When you run the sample it will now throw ArgumentException here:
If I change Id to a property with { get; set; } and no parameters to the CTOR this exception is thrown:
System.ArgumentException: 'Expression of type 'System.Object' cannot be used for assignment to type 'System.Int32''