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: RepoDb.SqlServer Enum picking up 2 types when upgraded from 1.1.1 -> 1.1.2 #736

Closed
simmohall opened this issue Jan 14, 2021 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@simmohall
Copy link

Bug Description

When running a query using an enum in the WHERE clause, if I use 2 enum values, the first uses INT and the second uses the STRING value

Exception Message:

No exception from RepoDb, but the underlying SQL fails as it can't convert the column to 2 different data types

Generated T-SQL example
exec sp_executesql N'SELECT [source_system], [incoming_payload], [Id], [correlation_id], [event_type], [external_ticket_id], [internal_ticket_id], [created_timestamp], [arrival_timestamp], [completion_timestamp], [retries_remaining], [last_retry_timestamp], [Status], [error_description] FROM [incoming_event_queue] WHERE (([Status] = @Status) OR ([Status] = @Status_1)) ;',N'@Status int,@Status_1 nvarchar(4000)',@Status=0,@Status_1=N'awaiting_retry'

exception in T-SQL when manually executing the run SQL. 
Msg 245, Level 16, State 1, Line 10
Conversion failed when converting the nvarchar value 'awaiting_retry' to data type int.

Schema and Model:
create table incoming_event_queue(id int, status int)

_localDbContext.Connection.Query<IncomingQueueEvent>(e => e.Status == EventStatus.queued || e.Status == EventStatus.awaiting_retry)

And also the model that corresponds the schema.

[Map("incoming_event_queue")]
public class IncomingQueueEvent
{
public int Id { get; set; }
[TypeMap(DbType.Int32)]
public EventStatus Status { get; set; }
}

public enum EventStatus
    {
        queued = 0,
..
awaiting_retry = 4
}
}

Library Version:

Example: RepoDb v1.12.5 and RepoDb.SqlServer v1.1.2

(note: this worked ok in v1.1.1

@simmohall simmohall added the bug Something isn't working label Jan 14, 2021
@mikependon mikependon pinned this issue Jan 14, 2021
@mikependon
Copy link
Owner

Yeah, there were PRs in relation to this and we had introduced this logic. So this might had affected this.

But is very recommended to not use the TypeMap if you are using the model-based operation like Query. Would you be able to remove the TypeMap decoration from your model? RepoDB understand it and it will do the job for you.

Of course, unless otherwise you are not using the model-based operations like Execute<Methods>.

@mikependon
Copy link
Owner

Hopefully, that would work, but if that recommendation doesn't fix that, then we will investigate this further and revert back to you. Plus, we will also guard this with the Integration Tests.

@simmohall
Copy link
Author

Thanks for the quick reply! I will move to that recommendation and report back shortly

@simmohall
Copy link
Author

Thanks, i've removed the TypeMap. It then goes back to the default string conversion which i was trying to avoid. But from reading that link - i've now set Converter.EnumDefaultDatabaseType = DbType.Int32 and now it is correctly using ints for the enum.
Thanks :)

@mikependon
Copy link
Owner

It is still a bug as having a forced attribute TypeMap should be the one prevail at all cost. Can we leave this one open so I can track?

@simmohall
Copy link
Author

sure - reopening for tracking

@simmohall simmohall reopened this Jan 14, 2021
mikependon added a commit that referenced this issue Jan 20, 2021
@mikependon mikependon unpinned this issue Jan 23, 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
Projects
None yet
Development

No branches or pull requests

2 participants