-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Support for CHECK constraints #14673
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direction is good, but we should settle on the IModel
changes before moving forward.
/// <returns> An object that can be used to configure the check constraint. </returns> | ||
public virtual EntityTypeBuilder HasCheckConstraint( | ||
[NotNull] string name, | ||
[NotNull] string logicalExpression) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool to take a C# expression and use the query pipeline to generate the SQL. We have similar ideas for ToView()
.
If we did that, these could also be implemented for the in-memory provider (it would just evaluate the expression)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this becomes specific to relational (and we don't take C# expressions), we should call this sql instead of expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was also discussed at some point for expressing global filters, maybe we should track all places which could benefit from this in a new issue.
In any case, it will always be desirable to provide a raw SQL overload (for expressions which for any reason can't be expressed otherwise)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm liking the idea for the C# expression overload. Any pointers on where I could find examples of using the query pipeline to generate SQL like that already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think finalizing the raw SQL version is a good first goal - an expression overload isn't going to be a simple task... In addition the query pipeline is being redone at the moment, so it may not be the best timing. Finally, expression make sense in other places, not just this one, so it may be better to tackle them together later. So I'd recommend concentrating only on SQL for now - we know we want it anyway - but as @bricelam wrote make sure everything is compatible with adding expressions later.
Another crazy idea: We could create these by convention based on validation attributes:
|
Couple of things to consider if you want to support OOB
|
@bricelam Right, I think I've completed the review changes. One bit I'm not happy with is that CheckConstraints collection hangs off RelationalModelAnnotations which feels wrong as it relates to entity types so maybe it should live on RelationalEntityTypeBuilderAnnotations? |
src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeBuilderAnnotations.cs
Outdated
Show resolved
Hide resolved
It's fine for |
@Muppets Generally it's looking good, so it's time to rebase and squash so we can have a final review. |
@AndriySvyryd I know this might not be the right place to ask this but after a few touch and go moments rebasing and squash some other branches, do you guys have any tips on how you generally rebase and squash changes on a branch to master? |
@Muppets There's nothing specific to our repo that I can think of. It helps to rebase frequently, you can do it retroactively by rebasing to a specific older commit. |
Improved encapsulation for CheckConstraint annotations
@Muppets Thanks for your contribution! |
Note follow-up in #17085 |
Thanks @roji. Definitely felt light on the tests for this. |
Thought I would pick this up as it sounded easy enough. Turns out it was probably more of a fundamental change than I was expecting and I feel I'm slightly out of my depth.
I feel like I've missed a ton of unit tests along the way. Feel free to rip it apart or send me in a different direction if it's not implemented correctly. Designed by example on this one.
Summary of the changes
Fixes #14425