Repodb: Bug: Insert exception since 1.1.3 with mysql...

Created on 9 Feb 2021  路  15Comments  路  Source: mikependon/RepoDB

hi again

great to see the project moving forward to even better things - thanks for all the work :)

since the upgrade to 1.1.3 insertall<>() code that used to work (and old builds do still work) fails with the following exception:

Expression of type 'System.Int32' cannot be used for parameter of type 'System.Int64' of method 'Void set_id(Int64)'

what info would you need to guess at what might be causing this? the model is as follows:

using RepoDb.Attributes;

namespace dsync.Models
{
    [Map("zaudit_response")]
    class ZauditResponse
    {
        [Map("audit_id")]
        public long id { get; set; }
        public int code { get; set; }
        public string guid { get; set; }
        public string action { get; set; }
        public string table { get; set; }
        public string msg { get; set; }
    }
}

the table create is:

CREATE TABLE `zaudit_response` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `audit_id` BIGINT(20) NULL DEFAULT NULL,
    `code` INT(11) NULL DEFAULT NULL,
    `rtimestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    `guid` VARCHAR(30) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
    `action` VARCHAR(30) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
    `table` VARCHAR(30) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
    `msg` VARCHAR(2000) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `audit_id` (`audit_id`) USING BTREE,
    INDEX `table` (`table`) USING BTREE,
    INDEX `zaudit_response_rtimestamp_index` (`rtimestamp`) USING BTREE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB

as i said, if i run the app built with versions before 1.1.3 everything works as always

any help appreciated

Fixed bug deployed

All 15 comments

Can you share the exception or the stack trace?

i did put the exception message in there - do you need more?

i also changed the code to do Insert<> one at a time with the models and the exception happens on the first insert<> attempt - just fyi

at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
   at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection`1& arguments)
   at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
   at RepoDb.Reflection.Compiler.CompileDataEntityPropertySetter[TEntity](PropertyInfo property, Type targetType)
   at RepoDb.Reflection.Compiler.CompileDataEntityPropertySetter[TEntity](Field field)
   at RepoDb.Reflection.FunctionFactory.CompileDataEntityPropertySetter[TEntity](Field field)
   at RepoDb.FunctionCache.DataEntityPropertySetterCache`1.Get(Field field)
   at RepoDb.FunctionCache.GetDataEntityPropertySetterCompiledFunction[TEntity](Field field)
   at RepoDb.Contexts.Providers.InsertExecutionContextProvider.CreateInternal[TEntity](IDbConnection connection, IEnumerable`1 dbFields, String tableName, IEnumerable`1 fields, String commandText)
   at RepoDb.Contexts.Providers.InsertExecutionContextProvider.Create[TEntity](IDbConnection connection, String tableName, IEnumerable`1 fields, String hints, IDbTransaction transaction, IStatementBuilder statementBuilder)
   at RepoDb.DbConnectionExtension.InsertInternalBase[TEntity,TResult](IDbConnection connection, String tableName, TEntity entity, IEnumerable`1 fields, String hints, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
   at RepoDb.DbConnectionExtension.InsertInternal[TEntity,TResult](IDbConnection connection, String tableName, TEntity entity, IEnumerable`1 fields, String hints, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
   at RepoDb.DbConnectionExtension.Insert[TEntity](IDbConnection connection, TEntity entity, IEnumerable`1 fields, String hints, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder

raw stacktrace

Well, the property Id must be of type int not long. But if you wish to have auto conversion, then you can set the Converter.ConversionType = Automatic.

"id" comes from the web service but is actually the audit_id value and is a bigint - the db id column is just an int autoinc that is irrelevant - the [Map("audit_id")] establishes the relationship up to 2 versions ago - did this behaviour change then?

Hmmm. There should be no changes have been made that should affect the behavior, and if it does, then it is an issue. FYI: We had re-wrote our compiler from scratch starting version 1.12.x, thus many issues has been raised right after that, but they had all been addressed already. This issue reported might be one of the issue that has been affected by those changes.

I am afraid that the Id property is being mapped to the Id column even with that mapping via Map attribute, hopefully not. I am assuming that only issue is the type compatibility here and I will check this one out for you.

When do you need the fix?

Had you tried using the automatic conversion type?

the conversion of bigint to int is not what i want here - the value that gets rehydrated into the model is called "id" but actually has to go into the "audit_id" bigint column - i cannot change what the column is called as it comes from the web service so i have to get this into that table

this still works without problem with versions up to this and the previous release of the lib, then it breaks with this

obviously a fix, if one is reqd, would ideally be now now but of course i understand this is not how things work so i would ask that if you could put it as high up the list as you can, and get to it as soon as you can, then i can ask no more and would be tremendously grateful - i think it is amazing that you respond so quickly and do this work in the first place - so thanks whatever happens
:)

Okay, currently, I am a bit occupied, but if you can help me creating a very small console application that can replicate this problem using the v1.12.7 release. Attach your database script on the solution as well and then attach the small solution on this thread. I want to start fixing this one up for you and issue a beta ASAP.

will do - thanks

should i attach it here? or send it somewhere else?

Just attached it here. :) Thanks

Will get back to you on this on weekend and will probably issue you a fix before Monday.

amazing - can't thank you enough :)

The fix is now available at RepoDb v1.12.8-beta1. Please install this latest version of core library.

Install-Package RepoDb -version 1.12.8-beta1
Was this page helpful?
0 / 5 - 0 ratings