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)
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
)
@nphmuller Yes, that's how it would work. Though you might need to enable the convention first.
Notes from triage:
Would we simply do this in the external check constraint plugin instead? See https://github.com/efcore/EFCore.CheckConstraints/issues/5
Closing, to be done as part of an external plugin (https://github.com/efcore/EFCore.CheckConstraints/issues/5)
Most helpful comment
Would we simply do this in the external check constraint plugin instead? See https://github.com/efcore/EFCore.CheckConstraints/issues/5