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: Insert exception since 1.1.3 with mysql... #765

Closed
fake-fur opened this issue Feb 9, 2021 · 15 comments
Closed

Bug: Insert exception since 1.1.3 with mysql... #765

fake-fur opened this issue Feb 9, 2021 · 15 comments
Assignees
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed.

Comments

@fake-fur
Copy link
Contributor

fake-fur commented Feb 9, 2021

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

@mikependon mikependon self-assigned this Feb 9, 2021
@mikependon
Copy link
Owner

Can you share the exception or the stack trace?

@fake-fur
Copy link
Contributor Author

fake-fur commented Feb 9, 2021

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

@mikependon
Copy link
Owner

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.

@fake-fur
Copy link
Contributor Author

fake-fur commented Feb 9, 2021

"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?

@mikependon
Copy link
Owner

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?

@mikependon
Copy link
Owner

Had you tried using the automatic conversion type?

@fake-fur
Copy link
Contributor Author

fake-fur commented Feb 9, 2021

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
:)

@mikependon
Copy link
Owner

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.

@mikependon mikependon changed the title insert exception since 1.1.3 with mysql... Bug: Insert exception since 1.1.3 with mysql... Feb 9, 2021
@mikependon mikependon added the bug Something isn't working label Feb 9, 2021
@fake-fur
Copy link
Contributor Author

fake-fur commented Feb 9, 2021

will do - thanks

@fake-fur
Copy link
Contributor Author

fake-fur commented Feb 11, 2021

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

@mikependon
Copy link
Owner

Just attached it here. :) Thanks

@fake-fur
Copy link
Contributor Author

RepoDbInsertDemo.zip

@mikependon
Copy link
Owner

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

@fake-fur
Copy link
Contributor Author

amazing - can't thank you enough :)

mikependon added a commit that referenced this issue Feb 12, 2021
#765 - Fixes for "Bug: Insert exception since 1.1.3 with mysql..."
@mikependon mikependon added the fixed The bug, issue, incident has been fixed. label Feb 12, 2021
@mikependon
Copy link
Owner

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

@mikependon mikependon added the deployed Feature or bug is deployed at the current release label Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed.
Projects
None yet
Development

No branches or pull requests

2 participants