EfCore 8: Primitive collections in JSON documents error with init #32310
Labels
area-json
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
Problem
When using
init
for properties that are set up as a primitive collection saving them to the database works, but trying to materialize them leads to aSystem.ArgumentException: 'Expression must be writeable (Parameter 'left')'
.This happens with both MsSql as well as sqlite providers (probably all others as well, but have only tested those 2).
This does NOT happen when using a "plain" primitive collection as a top level property of an entity.
init
is fine here.Code and Repro
You can find a runnable sample showing the problem here: https://github.com/Jejuni/PrimitiveCollectionInJsonInitProblem
The code is adapted from the samples referenced in the documentation: https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/whatsnew#primitive-collections-in-json-documents
These are the entities and DbContext.
Note the only relevant change from the official sample is the change from
set
toinit
on the primitive collectionDaysVisited
.The code in
Program.cs
shows the problem:Exception Stack Trace
Include provider and version information
EF Core version: 8.0
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer / Sqlite)
Target framework: (e.g. .NET 8.0)
Operating system:
IDE: (e.g. Visual Studio 2022 17.8)
The text was updated successfully, but these errors were encountered: