question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Garioscommented, Feb 23, 2022

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

0reactions
mikependoncommented, Oct 6, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No coercion operator is defined between types 'System. ...
No coercion operator is defined between types 'System.DateTime' and 'System.Nullable`1[System.TimeSpan]' #23784.
Read more >
Expression Cast Error - No coercion operator is defined ...
When I hit "Cast" function I am getting following error: No coercion operator is defined between types 'System.Func`2[CommentUrlCommon,System.
Read more >
Advice on "no coercion operator is defined between types ' ...
Due to how MySql holds Booleans in Integer fields when the EF hits a boolean I get: "No coercion operator is defined between...
Read more >
Filter a column with custom type - "No coercion operator is ...
Hello! I'm trying to enable filtering on a column which is bound to a property of a object whose structure is something like...
Read more >
Error while patching: "No coercion operator is def...
I get the above error while trying to update records in my SQL able. I pulled data from this table into power apps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found