Skip to content

Microsoft.Data.Sqlite: Support Half #30931

@bricelam

Description

@bricelam
Contributor

Similar to how we handle float, we could use REAL in the database for these values.

Activity

ilmalte

ilmalte commented on May 19, 2023

@ilmalte
Contributor

Hey @bricelam, may I give a try to work on this?

Do you see this implementation for Sqlite only?

If so, I was thinking about starting from this class and create the mapping for the type.
src/EFCore.Sqlite.Core/Storage/Internal/SqliteTypeMappingSource.cs

Then I would cover the new type in the test Create_and_clone_with_converter.

public override void Create_and_clone_with_converter(Type mappingType, Type type)

Any guidance, suggestion or heads up?

bricelam

bricelam commented on May 19, 2023

@bricelam
ContributorAuthor

@ilmalte Sure, feel free to work on it! Yes, this issue is just about SQLite.

First, you'll need to add support for it in the ADO.NET provider. Just follow what we do for float. Here's the code for reading values: (Note, there's a bit of duplication required in this method.)

if (typeof(T) == typeof(float))
{
return (T)(object)GetFloat(ordinal);
}

And, here's the code for writing:

else if (type == typeof(float))
{
var value = (double)(float)_value;
BindDouble(value);
}

Then yeah, for the EF Core changes, the type mapper is the right place.

We should also update the scaffolding code which uses heuristics to determine the CLR type:

if (_floatTypes.Contains(baseColumnType))
{
if (min >= float.MinValue
&& max <= float.MaxValue)
{
column["ClrType"] = typeof(float);
continue;
}
_logger.OutOfRangeWarning(column.Name, table.Name, "float");
}

added this to the Backlog milestone on May 24, 2023
added a commit that references this issue on Jul 21, 2023
linked a pull request that will close this issue on Dec 13, 2024
added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

      Participants

      @bricelam@ajcvickers@roji@ilmalte

      Issue actions

        Microsoft.Data.Sqlite: Support Half · Issue #30931 · dotnet/efcore