mikependon / RepoDB

A hybrid ORM library for .NET.
Apache License 2.0
1.68k stars 122 forks source link

Bug: ulid type converter error in 1.13.0 after #1172

Open IfunJoework opened 2 months ago

IfunJoework commented 2 months ago

Bug Description

Referring to the previous isusses to create PropertyHandler, an error occurred during test execution. After lowering the version, it can be executed normally.

Exception Message:

ArgumentException: Expression of type 'System.String' cannot be used for parameter of type 'System.Ulid' of method 'Void set_Id(System.Ulid)' (Parameter 'arg0')
System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, string methodParamName, string argumentParamName, int index)
System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression arg0)
System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable<Expression> arguments)
RepoDb.Reflection.Compiler.CompileDataEntityPropertySetter(Type entityType, PropertyInfo property, Type targetType)
RepoDb.Reflection.Compiler.CompileDataEntityPropertySetter(Type entityType, Field field)
RepoDb.Reflection.FunctionFactory.CompileDataEntityPropertySetter(Type entityType, Field field)
RepoDb.FunctionCache+DataEntityPropertySetterCache.Get(Type type, Field field)
RepoDb.FunctionCache.GetDataEntityPropertySetterCompiledFunction(Type entityType, Field field)
RepoDb.Contexts.Providers.InsertExecutionContextProvider.CreateInternal(Type entityType, IDbConnection connection, IEnumerable<DbField> dbFields, string tableName, IEnumerable<Field> fields, string commandText)
RepoDb.Contexts.Providers.InsertExecutionContextProvider.Create(Type entityType, IDbConnection connection, string tableName, IEnumerable<Field> fields, string hints, IDbTransaction transaction, IStatementBuilder statementBuilder)
RepoDb.DbConnectionExtension.InsertInternalBase<TEntity, TResult>(IDbConnection connection, string tableName, TEntity entity, IEnumerable<Field> fields, string hints, Nullable<int> commandTimeout, string traceKey, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
RepoDb.DbConnectionExtension.InsertInternal<TEntity, TResult>(IDbConnection connection, string tableName, TEntity entity, IEnumerable<Field> fields, string hints, Nullable<int> commandTimeout, string traceKey, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
RepoDb.DbConnectionExtension.Insert<TEntity>(IDbConnection connection, TEntity entity, IEnumerable<Field> fields, string hints, Nullable<int> commandTimeout, string traceKey, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)

PropertyHandler:

public class UlidPropertyHandler : IPropertyHandler<string, Ulid>
{
    public Ulid Get(string input, ClassProperty options)
    {
        return Ulid.Parse(input);
    }

    public string Set(Ulid input, ClassProperty options)
    {
        return input.ToString();
    }
}

The same code will work fine with RepoDb 1.12.10 / 1RepoDb.SqlServer .1.5

Library Version:

RepoDb v1.13.1 and RepoDb.SqlServer v1.13.1