Add Half type support for SQLite (#30931)#37481
Conversation
bricelam
left a comment
There was a problem hiding this comment.
Looking good to me.
You should also add logic for Half to SqliteDatabaseModelFactory.
|
For reference, the previous attempt was #35328 |
|
Thanks again @bricelam — I pushed updates addressing the feedback:
(Also, thanks to AndriySvyryd for pointing me to the previous attempt.) |
249ae47 to
6b86657
Compare
|
@kimjaejung96 Sorry for the delay. Please rebase on latest main and use |
There was a problem hiding this comment.
Pull request overview
This PR adds System.Half (16-bit floating point) support across the Microsoft.Data.Sqlite ADO.NET layer and the EF Core SQLite provider, enabling reading/writing Half values and mapping them to SQLite REAL.
Changes:
- Added
GetFieldValue<Half>handling in Microsoft.Data.Sqlite and parameter binding support for Half (guarded by#if NET6_0_OR_GREATER). - Introduced
SqliteHalfTypeMappingand registered it inSqliteTypeMappingSourcefor EF Core SQLite. - Updated scaffolding type inference/default parsing for
HALF, and added provider + ADO.NET tests for mapping and SQL literal generation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.Data.Sqlite.Tests/SqliteDataReaderTest.cs | Adds tests validating GetFieldValue<Half> behavior. |
| test/EFCore.Sqlite.Tests/Storage/SqliteTypeMappingTest.cs | Adds SQL literal generation test for Half. |
| test/EFCore.Sqlite.Tests/Storage/SqliteTypeMappingSourceTest.cs | Extends mapping coverage tests to include Half/Half?. |
| src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs | Adds Half support in GetFieldValue<T> under NET6_0_OR_GREATER. |
| src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs | Adds Half parameter binding and type inference under NET6_0_OR_GREATER. |
| src/EFCore.Sqlite.Core/Storage/Internal/SqliteTypeMappingSource.cs | Registers the new Half mapping for CLR type Half. |
| src/EFCore.Sqlite.Core/Storage/Internal/SqliteHalfTypeMapping.cs | New type mapping for Half stored as SQLite REAL. |
| src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs | Adds scaffolding recognition/inference/default parsing support for HALF. |
| public SqliteHalfTypeMapping(string storeType) | ||
| : base( | ||
| new RelationalTypeMappingParameters( | ||
| new CoreTypeMappingParameters(typeof(Half)), | ||
| storeType)) | ||
| { |
There was a problem hiding this comment.
@kimjaejung96 Can you also do this? You can add the JsonHalfReaderWriter in Core and also return it from https://github.com/dotnet/efcore/blob/main/src/EFCore/Storage/Json/JsonValueReaderWriterSource.cs#L37
- Add Half support in SqliteValueReader.GetFieldValue<T> - Add Half binding in SqliteValueBinder - Add SqliteHalfTypeMapping for EF Core SQLite provider - SQLite-specific implementation only (per maintainer feedback) - Use REAL store type, DbType is null (no DbType.Half exists) Fixes dotnet#30931
- Use GetDouble instead of GetFloat for Half reading (avoids extra conversion) - Add Half scaffolding support to SqliteDatabaseModelFactory - Add HALF, FLOAT16 type hints for Half CLR type mapping - Add Half range validation in REAL value type handling - Add Half default value parsing
Per reviewer feedback, keep only HALF for consistency with other floating-point type hints (SINGLE for float).
d2c4353 to
66dff1a
Compare
|
Thanks for the review. I've rebased onto the latest main and changed the new Half literal test from [ConditionalFact] to [Fact]. |
Summary
Add Half (16-bit floating point) type support for Microsoft.Data.Sqlite and EF Core SQLite provider.
Fixes #30931
Changes
Microsoft.Data.Sqlite (ADO.NET layer)
GetFieldValue<Half>supportEF Core SQLite Provider
Tests
Design Notes
Based on #35328 feedback:
EFCore.Relational(no HalfTypeMapping in common layer)DbType-System.Data.DbTypehas no Half value, so DbType is null#if NET6_0_OR_GREATERfornetstandard2.0compatibility