-
Notifications
You must be signed in to change notification settings - Fork 14
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
Range check constraints not generated for some datatype #120
Comments
@molinch no, AFAIK there's not supposed to be such a limitation - can you please submit a minimal, runnable code sample? |
I created a repro sample at https://github.com/molinch/EntityFrameworkRelatedBugs
To save you time:
|
Thanks. Just to set expectations, it will take me a while to get around to investigating this, as there's a lot going on at the moment. |
I am already grateful that you will look into this 👍 |
Just encountered this with a |
It's not working for EFCore.CheckConstraints/EFCore.CheckConstraints/Internal/ValidationCheckConstraintConvention.cs Lines 111 to 118 in 0a7422d
As RangeAttribute only accepts int or double as arguments, the piece of code mentioned above will reject the attribute if the property type is float or decimal , for instance, so nothing will happen.
@roji what do you suggest here? Should we have a list of acceptable types instead of just comparing dynamically? I think they would be: |
Looking at the code, simply accepting other types and trying to pass them into the type mapping's GenerateSqlLiteral may or may not work (depending on what that function expects and how strict it is).. So I think it would be safer to convert to the target type first (i.e. have a set of conversions for int, and another for double). How does that sound? |
@roji Since it's possible to write |
I don't think that's a good idea - I'm not sure all databases accept (i.e. implicitly convert) 1.2 as int, and even if they did, I wouldn't want to see 1.0 in my SQL when a simple int was passed to Regarding the rest, I'm afraid I don't understand what you mean exactly, e.g. what does "looking for an operator in the database" mean? Maybe submit a quick code sample or similar to illustrate? |
@roji I don't think that what's happening is an implicit conversion between |
@Logerfo this plugin can't start sending queries to the database in order to know whether operators exist - that is well beyond its scope. In addition, the plugin needs to do its work in situations where there's no database at all, e.g. when adding a new migration. The task here is really not that hard - just a small static translation table from the two types actually supported by [Range] (int and long) to the CLR type of the type mapping of the property. |
Stumbled into this for a The fix for me was to do like This workaround might only work if you are using the three-parameter attribute constructor, though... at least, I didn't test it with the others. |
It seems like Range check constraints aren't always generated. If the datatype is
int
it always works, however if we usebyte
orfloat
then it's not always generating them.Are you aware of this limitation? I can probably create a sample that demonstrates this.
The text was updated successfully, but these errors were encountered: