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

IMapper.GetParameterConverter sourceType parameter Is a different type between Insert and Update #701

Open
vllama opened this issue May 30, 2024 · 1 comment

Comments

@vllama
Copy link

vllama commented May 30, 2024

When updating a table with an array column, malformed sql is being created because the sourceType is passed in as the Array Element Type instead of the Array Type, but only when updating. When Inserting the proper type is being passed in in sourceType

public override Func<object, object> GetParameterConverter(DbCommand command, Type sourceType) {
if (sourceType == typeof(int[])) {  //<-- this is int when updating  should be int[] like when inserting.
				return x => new NpgsqlParameter {
					NpgsqlDbType = NpgsqlDbType.Array | NpgsqlDbType.Integer,
					Value = (int[])x
				};
}

See parameters 20 and 21 in the update. Sql is not valid.
Causes:
Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "$22"

UPDATE TBL SET "help" = @p0,...  "status_values" = @p20,@p21, "id_event" = @p22, "deleted" = @p23, "sys_created_by" = @p24, "sys_created_on" = @p25, "sys_modified_by" = @p26, "sys_modified_on" = @p27 WHERE "id" = @p28
...
         -> @p20 [Int32] = "2"
	 -> @p21 [Int32] = "3"

INSERT INTO TBL ("help", ... "status_values","id_event","deleted","sys_created_by","sys_created_on","sys_modified_by","sys_modified_on") VALUES (@p0... @p20,@p21,@p22,@p23,@p24,@p25,@p26) returning "id" as NewID
...
	 -> @p20 [Int32[]] = "System.Int32[]"
@vllama
Copy link
Author

vllama commented May 30, 2024

Version 5.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant