Skip to content

Commit

Permalink
Make check constraints work when creating a table
Browse files Browse the repository at this point in the history
Follow-up to #14673
  • Loading branch information
roji committed Aug 11, 2019
1 parent 72e057c commit 619b1d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ protected virtual IEnumerable<MigrationOperation> Add(
createTableOperation.UniqueConstraints.AddRange(
target.GetKeys().Where(k => !k.IsPrimaryKey()).SelectMany(k => Add(k, diffContext))
.Cast<AddUniqueConstraintOperation>());
createTableOperation.CheckConstraints.AddRange(
target.GetCheckConstraints().SelectMany(c => Add(c, diffContext))
.Cast<CreateCheckConstraintOperation>());

foreach (var targetEntityType in target.EntityTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void Create_table()
x.Property<int?>("ParentAltId");
x.HasOne("Node").WithMany().HasForeignKey("ParentAltId");
x.HasIndex("ParentAltId");
x.HasCheckConstraint("SomeCheckConstraint", "[Id] > 10");
}),
upOps =>
{
Expand All @@ -255,7 +256,7 @@ public void Create_table()
Assert.Null(createTableOperation.Columns.First(o => o.Name == "AltId").DefaultValue);
Assert.NotNull(createTableOperation.PrimaryKey);
Assert.Equal(1, createTableOperation.UniqueConstraints.Count);
Assert.Equal(0, createTableOperation.CheckConstraints.Count);
Assert.Equal(1, createTableOperation.CheckConstraints.Count);
Assert.Equal(1, createTableOperation.ForeignKeys.Count);

Assert.IsType<CreateIndexOperation>(upOps[2]);
Expand Down

0 comments on commit 619b1d4

Please sign in to comment.