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

Check constraint validation attribute convention #15410

Closed
AndriySvyryd opened this issue Apr 18, 2019 · 5 comments
Closed

Check constraint validation attribute convention #15410

AndriySvyryd opened this issue Apr 18, 2019 · 5 comments

Comments

@AndriySvyryd
Copy link
Member

Suggested by @bricelam:

Attribute Expression
[Compare("Y")] X == Y
[MinLength(8)] X.Length >= 8
[Range(0, 10)] X >= 0 && X <= 10
[RegularExpression("[0-9A-F]+") Regexp.IsMatch(X, "[0-9A-F]+")
[DataType(...)] (predefined regular expressions)
@nphmuller
Copy link

nphmuller commented Apr 19, 2019

If this enhancement was implemented, would the following case be supported?

When I add the [Range(0, 10)] attribute to my model, the following migration SQL statements will be generated:

ALTER TABLE MyModel
ADD CONSTRAINT CK_Table_Column_Range CHECK (
   Column >= 0 AND Column <= 10
)

@AndriySvyryd
Copy link
Member Author

@nphmuller Yes, that's how it would work. Though you might need to enable the convention first.

@ajcvickers
Copy link
Member

Notes from triage:

  • We should make sure if we do this that it doesn't cause unwanted breaking change or perf impact.
  • Could apply to reverse-engineering or creating migrations.

@roji
Copy link
Member

roji commented Aug 27, 2020

Would we simply do this in the external check constraint plugin instead? See efcore/EFCore.CheckConstraints#5

@roji
Copy link
Member

roji commented Aug 28, 2020

Closing, to be done as part of an external plugin (efcore/EFCore.CheckConstraints#5)

@roji roji closed this as completed Aug 28, 2020
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants