EF Code First - Fluent API (WithRequiredDependent and WithRequiredPrincipal)
问题 I have the following class: public class User { public Guid Id { get; set; } public string Name { get; set; } public Couple Couple { get; set; } } public class Couple { public Guid Id { get; set; } public User Groom { get; set; } public User Bride { get; set; } } Important points: Bride and Groom properties are required One-to-one relationship In the User class, it is Couple required DbContext in OnModelCreating modelBuilder.Entity<User>().HasRequired(u => u.Couple).WithRequiredPrincipal();