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

Are ValueConverterAttributes supported? #5

Closed
nils-a opened this issue Feb 18, 2021 · 6 comments
Closed

Are ValueConverterAttributes supported? #5

nils-a opened this issue Feb 18, 2021 · 6 comments

Comments

@nils-a
Copy link

nils-a commented Feb 18, 2021

I have a setup where I use a simple ValueConverterAttribute to save enums as String in the database.
Using StaTypPocoQueries.PetaPoco for querying of those pocos results in errors like:

SqlException: Conversion failed when converting the nvarchar value 'SomeValue' to data type int

I'm using database.SingleOrDefaultAsync(x => x.SomeString == "SomeString" && x.SomeEnum == MyEnumType.SomeValue)

Now, in "pure" PetaPoco I did not have the problem, but I also had database.SingleOrDefaultAsync(Sql.Builder.Where("[SomeString] = @0 AND [SomeEnum] = @1", "SomeString", Enum.GetName(typeof(MyEnumType), MyEnumType.SomeValue)) - which is to say I did the conversion of the Converter manually in code.

So I guess the question really is: Am I doing something wrong, or this this not a supported case to do?

@asherber
Copy link
Owner

asherber commented Feb 18, 2021

I see what you're trying to do, and I agree that it would be useful. But it's not currently supported.

This library is just a set of bindings between the underlying StaTypPocoQueries library, which handles the translation between the Expression<Func<T, bool>> and a SQL query with parameters. If you want the translator to be smart enough to apply value converters, you'll need to open a ticket in the other library. Right now, all it's doing is turning x.SomeEnum into a column name and MyEnumType.SomeValue into a parameter; it's not caring about types.

@nils-a
Copy link
Author

nils-a commented Feb 18, 2021

I have opened d-p-y/statically-typed-poco-queries#8 to track my request.

@nils-a nils-a closed this as completed Feb 18, 2021
@d-p-y
Copy link

d-p-y commented Feb 25, 2021

Hi, I've implemented support for this feature in StaTypPocoQueries.Core. See issue #8 for more info.

@asherber
Copy link
Owner

@d-p-y Thank you! I'll take a look and add the corresponding hooks in this library.

@asherber
Copy link
Owner

This is now supported by v1.4.1. Thanks to @d-p-y for the support.

@nils-a
Copy link
Author

nils-a commented Feb 27, 2021

Thanks @asherber and @d-p-y for getting this done so quickly. 🙇
I will try to implement it next week!

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

3 participants