Skip to content

hasmany mapping

Todd Thomson edited this page Aug 17, 2018 · 4 revisions

1-Many Relationships

To configure a 1-Many relationship on an entity property use the HasMany() method.

entity.HasMany( p => p.Orders )
    .WithForeignKey<Order>( p => p.CustomerId )
    .References<Customer>( p => p.Id );

In the above example:

  • The .HasMany() lambda expression specifies the entity relationship property.
  • The .WithForeignKey<TFKEntity>() lambda expression specifies the entity foreign key property.
  • The .References<TRefEntity>() lambda expression specifies the foreign key reference entity and (usually) primary key.