You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, tried to see if this issue was reported already, but couldn't find anything (though it's most likely related to an open issue somewhere).
I have encountered an issue when an entity with a nullable boolean property is mapped to a JSON column via the ToJson method.
When saving the entity to the database, the boolean property is saved in a string format { "MyBooleanProperty": "false" }. But when reading the entity from the database an exception is thrown.
Exception:
System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable`1[System.Boolean]. Path: $ | LineNumber: 0 | BytePositionInLine: 6. ---> System.InvalidOperationException: Cannot get the value of a token type 'String' as a boolean.
I previously reported a similar issue related to enums in issue #30598 that was a duplicate of issue #30330 . It was stated in issue #30598 that the issue in #30330 did not only affect enums, but all non string values, leading me to belive it might be related to this issue. The difference in this case is that there are no converters involved (at least not explicitly provided by me 😄).
Code/reproduction
Here is a small solution containing a single unit test that recreates the issue (access to a database is required to run, see connection string on line 56): EFJsonBooleanIssues.zip
Versions
EF Core version: 7.0.7
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
IDE: Visual Studio Professional 2022 17.5.5
The text was updated successfully, but these errors were encountered:
I didn't get the exception - the code executes just fine, producing the following sql:
SELECT TOP(1) [m].[Id], [m].[MyJsonProperty]
FROM [MyEntity] AS [m]
and the following result:
Id: 1, MyJsonProperty: {"MyBooleanProperty":true}
just to clarify, i'm trying on current dev bits in main branch (i.e. future 8.0) - it must have gotten fixed as part of some other issue, but not necessarily patched into 7.0.x, so the bug report was completely valid.
Hello, tried to see if this issue was reported already, but couldn't find anything (though it's most likely related to an open issue somewhere).
I have encountered an issue when an entity with a nullable boolean property is mapped to a JSON column via the ToJson method.
When saving the entity to the database, the boolean property is saved in a string format
{ "MyBooleanProperty": "false" }
. But when reading the entity from the database an exception is thrown.Exception:
Stack trace:
I previously reported a similar issue related to enums in issue #30598 that was a duplicate of issue #30330 . It was stated in issue #30598 that the issue in #30330 did not only affect enums, but all non string values, leading me to belive it might be related to this issue. The difference in this case is that there are no converters involved (at least not explicitly provided by me 😄).
Code/reproduction
Here is a small solution containing a single unit test that recreates the issue (access to a database is required to run, see connection string on line 56): EFJsonBooleanIssues.zip
Versions
EF Core version: 7.0.7
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
IDE: Visual Studio Professional 2022 17.5.5
The text was updated successfully, but these errors were encountered: