-
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
Adds unexpected constraints when using together with [Required] attribute #151
Comments
@hmundle can you please post a quick code sample showing the code that worked before 8.0 and now fails? That's always much better than trying to describe the situation with words. |
For testing the issue I used https://github.com/efcore/EFCore.CheckConstraints repository, tag v8.0.1 and v7.0.2. On v8.0.1 I updated
On v7.0.2 to:
Test |
I have a similar problem after updating from 7.0.2 to 8.0.1 with MS SQL Server. My version properties for optimistic concurrency checks are implemented like this: [Timestamp, Required]
public byte[]? Version { get; set; } EFCore.CheckConstraints 8.0.1 now creates a new unnecessary MinLength constraint for this: t.HasCheckConstraint("CK_TodoItems_Version_MinLength", "LEN([Version]) >= 1"); Using |
I can confirm this is not only a problem with Postgres. In SQL server I get an exception building the model as it tries to add to check constraints with the same name on the same table. It does seem that it creates a MinLength constraints both for Required and StringLength with MinimumLength set. Like this property:
Like cremor wrote it can be circumvented by setting AllowEmptyStrings to true. |
When updating to version 8,
EFCore.CheckConstraints
breaks EF code first usage.I mainly use Postgres.
It turned out, that the usage of
[Required]
attribute creates additional constraints, which did not show up in version 6 (and probably in version 7).[Range(1, 5)]
on type int,MinLength
will added, at least with Postgres this will fail, becauseLENGTH()
is only supported for stringsId
property of type int, the same will happenStringLength()
twoMinLength
constraints will be added, which fails immediately.This can be tested easily with
EFCore.CheckConstraints.Test
unit tests:Add
[Required]
toBlog.Id
,Blog.Rating
andBlog.Required
.Add this test as well:
It would be great, if this situation can be improved.
The text was updated successfully, but these errors were encountered: