-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Jiri Cincura ↹ <[email protected]>
…reate json reader writer
public HalfTypeMapping( | ||
string storeType, | ||
DbType? dbType = System.Data.DbType.Single) | ||
: this(new RelationalTypeMappingParameters( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. | |||
|
There was a problem hiding this comment.
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()) | ||
{ | ||
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?> |
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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.
Fixes #30931
Also I want to discuss with team, what shall I change in migration and compiled models, because I a little bit misunderstanding