public class Vehicle { [Key] public int Id { get; set; } public virtual Boat Boat { get; set; } }
public class Boat { [Key] public int Id { get; set; } [ForeignKey("Id")] public virtual Vehicle { get; set; } }
protected override void OnModelCreating(ModelBuilder mb) { // ... other code ... mb.Entity<Boat>() .HasOne(x => x.Vehicle) .WithOne(x => x.Boat) .IsRequired(false) .OnDelete(DeleteBehavior.Restrict); // ... other code ... }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.