Skip to content

Adds unexpected constraints when using together with [Required] attribute #151

@hmundle

Description

@hmundle

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).

  • together with [Range(1, 5)] on type int, MinLength will added, at least with Postgres this will fail, because LENGTH() is only supported for strings
  • together with the Id property of type int, the same will happen
  • together with StringLength() two MinLength constraints will be added, which fails immediately.

This can be tested easily with EFCore.CheckConstraints.Test unit tests:
Add [Required] to Blog.Id, Blog.Rating and Blog.Required.

Add this test as well:

    [Fact]
    public virtual void RequiredNoString()
    {
        var entityType = BuildEntityType<Blog>();

        var constraints = entityType.GetCheckConstraints();
        Assert.DoesNotContain(constraints, c => c.Name == "CK_Blog_Id_MinLength");
        Assert.DoesNotContain(constraints, c => c.Name == "CK_Blog_Rating_MinLength");
    }

It would be great, if this situation can be improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions