When we have a one-to-many relationship, we can say that a record in one table is related to multiple records in another table.
An example of a one-to many relationship would be between a user and game sessions. Assuming that we have a User class and a GameSession class, the one-to-many relationship can be represented with the Fluent API as follows:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.HasOne(u => u.GameSession)
.WithMany(g => g.User)
.HasForeignKey<GameSession>(u => u.UserForeignKey);
}
The preceding code snippet still uses the .HasOne() property, but the difference is that it is chained to a .HasMany() property, making it a one-to many relationship.