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 required- One-to-one relationships
User class requires Couple
DbContext in OnModelCreating
modelBuilder.Entity<User>().HasRequired(u => u.Couple).WithRequiredPrincipal(); modelBuilder.Entity<Couple>().HasRequired(u => u.Bride).WithRequiredDependent(); modelBuilder.Entity<Couple>().HasRequired(u => u.Groom).WithRequiredDependent();
But I canβt be obligatory!
All records with zero value in the database!
How to get fields in a database as non-empty? If possible using the Flient API .
entity-relationship ef-code-first fluent-interface
ridermansb
source share