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

Insert Error #313

Open
Kudiyarasu26 opened this issue Jan 25, 2023 · 1 comment
Open

Insert Error #313

Kudiyarasu26 opened this issue Jan 25, 2023 · 1 comment

Comments

@Kudiyarasu26
Copy link

Object of type 'System.Int64' cannot be converted to type 'System.Int32
Show this type of the Error But Values Insert In Table

@jchamberlain-pcty
Copy link

I just ran into this myself. This comes from the library trying to update your DTO with the inserted identity. It assumes the identity is a long:
https://github.com/tmsmith/Dapper-Extensions/blob/master/DapperExtensions/DapperImplementor.cs#L613

So when it tries to update your DTO to set the identity value, it throws that exception:
https://github.com/tmsmith/Dapper-Extensions/blob/master/DapperExtensions/DapperImplementor.cs#L710

This means it successfully inserted the item (which is why you saw it in the table), but throws an exception processing the result.

I've seen on StackOverflow that the general advise seems to be to use a different key type in your table, such as a GUID or BIGINT.

To anyone thinking of submitting a PR for this, keep in mind that every SQL Dialect may need to be updated too. For instance, the SqlServerDialect casts the scope identity to a bigint:
https://github.com/tmsmith/Dapper-Extensions/blob/master/DapperExtensions/Sql/SqlServerDialect.cs#L23

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

2 participants