FluentNHibernate Documentation

repository·main·Indexed 23 days ago

https://github.com/nhibernate/fluent-nhibernate

A library providing a fluent, XML-less, and compile-safe way to define mappings for NHibernate using C# code and conventions. It supports both Auto-mapping via IAutomappingConfiguration and explicit Fluent mapping for fine-grained control over object-relational mappings.

Tokens
530
Snippets
1
Records
4
Agent score
32%

What's inside FluentNHibernate

  1. Choose between Auto-mapping and Fluent mapping

    main

    FluentNHibernate provides two primary ways to define your object-relational mappings:

    1. Auto-mapping: Uses conventions to automatically map your domain objects to the database.
    2. Fluent mapping: Provides a fluent interface for explicit, fine-grained control over how your objects and properties are mapped.

    Decide which approach best suits your application's complexity and requirements.

  2. Configure Automapping using IAutomappingConfiguration

    main

    The AutoMappingExpressions class is obsolete. To customize how FluentNHibernate automaps your entities, you should instead implement or use an instance of IAutomappingConfiguration.

    Instead of setting delegates on AutoMappingExpressions, you should override the following methods in your configuration implementation to control mapping behavior:

    • ShouldMap(Member member): Determines whether a specific member should be automapped.
    • IsId(Member member): Determines if a member is the identity (primary key) of an entity.
    • GetParentSideForManyToMany(Type left, Type right): Specifies which side is the parent in a many-to-many relationship.
    • IsConcreteBaseType(Type type): Determines if a type is a concrete base type.
    • IsComponent(Type type): Determines if a type is a component.
    • GetComponentColumnPrefix(Member member): Specifies the column prefix for component members.
    • IsDiscriminated(Type type): Determines if a type uses a discriminator column.
    • GetDiscriminatorColumn(Type type): Returns the name of the discriminator column.
    • AbstractClassIsLayerSupertype(Type type): Determines if an abstract class is a layer supertype or part of the mapped hierarchy.
    • SimpleTypeCollectionValueColumn(Member member): Specifies the value column used for collections of simple types.