Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Half type support for SqlLite #35328

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

newmasterSG
Copy link

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • [x ] The code builds and tests pass locally (also verified by our automated build checks)
  • [x ] Commit messages follow this format:
        Summary of the changes
        - Adding half type mapping for sql lite and double to half convertor.

        

Fixes #30931

  • [ x] Tests for the changes have been added (for bug fixes / features)
  • [x ] Code follows the same patterns and style as existing code in this repo

Also I want to discuss with team, what shall I change in migration and compiled models, because I a little bit misunderstanding

@newmasterSG newmasterSG requested a review from a team as a code owner December 13, 2024 13:47
public HalfTypeMapping(
string storeType,
DbType? dbType = System.Data.DbType.Single)
: this(new RelationalTypeMappingParameters(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to call here base(storeType, typeof(Half), dbType, jsonValueReaderWriter: JsonHalfReaderWriter.Instance) directly.

/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class SqlliteHalfTypeMapping : HalfTypeMapping
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SqlliteHalfTypeMapping -> SqliteHalfTypeMapping

@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Extra empty line.

public DoubleToHalfConverter()
: this(new())
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Extra empty line.

/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override string GenerateNonNullSqlLiteral(object value)
=> new DoubleTypeMapping(StoreType).GenerateSqlLiteral((double)(Half)value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs specific implementation.

/// </summary>
public HalfTypeMapping(
string storeType,
DbType? dbType = System.Data.DbType.Single)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.Data.DbType.Single is not correct here. Given that there's no Half in System.Data.DbType, I think we can have just specific implementation for SQLite.

/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-value-converters">EF Core value converters</see> for more information and examples.
/// </remarks>
public class DoubleToHalfConverter : ValueConverter<double?, Half?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this converter? SQLite is going to handle Half "natively". And for other databases writing converter is super simple, especially given you can freely choose whether it's going to be double or float or whatever.

@@ -176,6 +177,7 @@ public void Does_mappings_for_store_type(string storeType, Type clrType, DbType?
[InlineData("REAL", typeof(float), DbType.Single)]
[InlineData("UNREALISTIC", typeof(float), DbType.Single)]
[InlineData("RUBBISH", typeof(float), DbType.Single)]
[InlineData("RUBBISH", typeof(Half?), DbType.Single)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're missing some values here for completeness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft.Data.Sqlite: Support Half
2 participants