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

Bug: No coercion operator is defined between types 'System.TimeSpan' and 'System.Int64'. #1033

Closed
Garios opened this issue Feb 21, 2022 · 10 comments
Assignees
Labels
bug Something isn't working fixed The bug, issue, incident has been fixed.

Comments

@Garios
Copy link

Garios commented Feb 21, 2022

Hi, I updated from 1.12.9 to 1.12.10 (using C#). The following property-handler doesn't work. It works for reading, but not for writing (insert/update). (I mentioned it in #1021)

public class TestClass
{
  public long ID {get;set;}
  public TimeSpan TestFieldTimeSpan {get;set;}
}
    public class PropertyHandlerTimeSpan : IPropertyHandler<long, TimeSpan>
    {
        public TimeSpan Get(long p, ClassProperty property) => new TimeSpan(p);

        public long Set(TimeSpan p, ClassProperty property) => p.Ticks;
    }
FluentMapper.Entity<TestClass>().PropertyHandler<PropertyHandlerTimeSpan>(p=>p.TestFieldTimeSpan );

Exception: "Compiler.Entity/Object.Property: Failed to convert the value expression for property handler 'PropertyHandlerTimeSpan'. ClassProperty :: Name = TestFieldTimeSpan (System.TimeSpan), DeclaringType = TestClass

   at RepoDb.Reflection.Compiler.GetEntityInstancePropertyValueExpression(Expression entityInstanceExpression, ClassProperty classProperty, DbField dbField)
   at RepoDb.Reflection.Compiler.GetDataEntityDbParameterValueAssignmentExpression(ParameterExpression parameterVariableExpression, Expression entityExpression, ParameterExpression propertyExpression, ClassProperty classProperty, DbField dbField, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.GetDataEntityParameterAssignmentExpression(ParameterExpression commandParameterExpression, Int32 entityIndex, Expression entityExpression, ParameterExpression propertyExpression, DbField dbField, ClassProperty classProperty, ParameterDirection direction, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.GetPropertyFieldExpression(ParameterExpression commandParameterExpression, Expression entityExpression, FieldDirection fieldDirection, Int32 entityIndex, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.CompileDataEntityDbParameterSetter(Type entityType, IEnumerable`1 inputFields, IEnumerable`1 outputFields, IDbSetting dbSetting)
   at RepoDb.Reflection.FunctionFactory.CompileDataEntityDbParameterSetter(Type entityType, IEnumerable`1 inputFields, IEnumerable`1 outputFields, IDbSetting dbSetting)
   at RepoDb.FunctionCache.DataEntityDbParameterSetterCache.Get(Type entityType, String cacheKey, IEnumerable`1 inputFields, IEnumerable`1 outputFields, IDbSetting dbSetting)
   at RepoDb.FunctionCache.GetDataEntityDbParameterSetterCompiledFunction(Type entityType, String cacheKey, IEnumerable`1 inputFields, IEnumerable`1 outputFields, IDbSetting dbSetting)
   at RepoDb.Contexts.Providers.UpdateExecutionContextProvider.CreateInternal(Type entityType, IDbConnection connection, String tableName, IEnumerable`1 dbFields, IEnumerable`1 fields, String commandText)
   at RepoDb.Contexts.Providers.UpdateExecutionContextProvider.<CreateAsync>d__2.MoveNext()

Inner Exception: "No coercion operator is defined between types 'System.TimeSpan' and 'System.Int64'."

   at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
   at RepoDb.Reflection.Compiler.ConvertExpressionToTypeExpression(Expression expression, Type toType)
   at RepoDb.Reflection.Compiler.ConvertExpressionToNullableExpression(Expression expression, Type targetNullableType)
   at RepoDb.Reflection.Compiler.ConvertExpressionToPropertyHandlerSetExpressionTuple(Expression expression, ClassProperty classProperty, Type targetType)
   at RepoDb.Reflection.Compiler.ConvertExpressionToPropertyHandlerSetExpression(Expression expression, ClassProperty classProperty, Type targetType)
   at RepoDb.Reflection.Compiler.GetEntityInstancePropertyValueExpression(Expression entityInstanceExpression, ClassProperty classProperty, DbField dbField)
@Garios Garios added the bug Something isn't working label Feb 21, 2022
@mikependon
Copy link
Owner

I was a bit surprise by this issue as our Integration Tests are working. The only difference is just we are using DateTime to DateTime but the others (like this) are almost the same concepts. I can even replicate this issue (just now).

We will fix this one for you as this is a bit critical to be honest. You will receive further updates from us in relation to this.

Working: RepoDbPropertyHandler-CustomType-Working.zip
Not Working: RepoDbPropertyHandler-TimeSpan-NotWorking.zip

mikependon added a commit that referenced this issue Feb 22, 2022
#1033 - fixed the issue on the property handler for TimeSpan and Int/…
@mikependon
Copy link
Owner

This has just been fixed and it will be available on the next release. Would you be able to let us know if you the fix immediately? Thanks

@mikependon mikependon added the fixed The bug, issue, incident has been fixed. label Feb 22, 2022
@Garios
Copy link
Author

Garios commented Feb 23, 2022

Hi, thank you! I tried it with the current master. Now it works fine! Thanks!! I will wait till the next release for using 1.12.10.
Thanks!

@mikependon
Copy link
Owner

This is the only fix for that (fd973c3#diff-60f2ffa37fb8c5f1593dd214b314d6b037e40b4a1a3a681a4f1e591dbd1f5652R903), but we covered it by the Integration Tests.

Alternatively, you use the newly release v1.12.10 but you have to make the property nullable.

Model:

image

Table:

image

Property Handler:

image

@Garios
Copy link
Author

Garios commented Feb 23, 2022

Thank you for this hint, but currently it's not absolutely necessary to use 1.12.10 😉

@Garios
Copy link
Author

Garios commented Oct 6, 2022

Hello Mike,
when do you plan the next release? I need this fix, because of another fix.
kind regards
Juergen

@mikependon
Copy link
Owner

I can issue a new beta for you later. I will update this ticket

@Garios
Copy link
Author

Garios commented Oct 6, 2022

wow, this would be nice! Thank you!

@mikependon
Copy link
Owner

The latest alpha release has been pushed. Please install the package >= RepoDb v1.13.0-2 and its equivalent extension package.
Note: We cannot issue a beta due to a failing scenario in the latest development branch.

@mikependon
Copy link
Owner

Please be informed of our delta changes. In this release, we have so many breaking changes. This is the reason why we are having delays on our releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed The bug, issue, incident has been fixed.
Projects
None yet
Development

No branches or pull requests

2 participants