dotnet / dotnet/efcore

OwnedEntity why do I get DropForeignKey and CreateForeignKey for every new migration.

Open
#30,199 6 comments 0 reactions 0 assignees View on GitHub
area-model-building customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

I have a owned entity but for every add-migration it creates a migration that has a DropForeignKey and CreateForeignKey because I added OnDelete without the OnDelete (or using the default DeleteBehavior.Cascade) it stops behaving like that. Is there any reason why or is this a bug.

public class OrderConfiguration : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.OwnsMany(x => x.OrderLines, orderLine =>
{
orderLine.HasOne(x => x.Order).WithMany(x => x.OrderLines)
.OnDelete(DeleteBehavior.ClientCascade); // <--- This triggers the migration to be generated every time.
});
}
}

.NET 6 EF Core 6.0.13

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.