Skip to content

Commit f044574

Browse files
author
Bart Koelman
committed
Clarified comment
1 parent 8806a04 commit f044574

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

test/JsonApiDotNetCoreExampleTests/IntegrationTests/RequiredRelationships/DefaultBehaviorDbContext.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ protected override void OnModelCreating(ModelBuilder builder)
2424
.WithOne(order => order.Customer)
2525
.IsRequired();
2626

27+
// By default, EF Core generates an identifying foreign key for a required 1-to-1 relationship.
28+
// This means no foreign key column is generated, instead the primary keys point to each other directly.
29+
// That mechanism does not make sense for JSON:API, because patching a relationship would result in
30+
// also changing the identity of a resource. Therefore we need to add an explicit foreign in this case.
2731
builder.Entity<Order>()
2832
.HasOne(order => order.Shipment)
2933
.WithOne(shipment => shipment.Order)
30-
// Without specifying "OrderId", the primary key will be used as a foreign key which would result in attempt to update the shipment identity when this relationship is patched.
3134
.HasForeignKey<Shipment>("OrderId")
3235
.IsRequired();
3336
}

0 commit comments

Comments
 (0)