Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is an issue with Fluent NHibernate 2.1's validation/pairing of relationships. FNH <a href="https://github.com/jagregory/fluent-nhibernate/blob/release-1.2/src/FluentNHibernate/Visitors/RelationshipPairingVisitor.cs" rel="noreferrer">pairs up relationships</a> and then <a href="https://github.com/jagregory/fluent-nhibernate/blob/release-1.2/src/FluentNHibernate/Visitors/ValidationVisitor.cs#L27" rel="noreferrer">validates that only one side of the relationship has <code>.Inverse()</code> specified</a>. Because both references (parent/child) are to the same class they are both candidate matches when pairing. In that case, FNH <a href="https://github.com/jagregory/fluent-nhibernate/blob/release-1.2/src/FluentNHibernate/Visitors/RelationshipPairingVisitor.cs#L113" rel="noreferrer">matches on name similarity</a>. Consequently, they each get paired with themselves rather than each other. So then placing <code>.Inverse()</code> on either one triggers the validation (both sides of the pair are the same relationship which is inverse).</p> <p>It should be possible to correct this using the <code>OverrideBiDirectionalManyToManyPairing()</code> method on the FluentMappingsContainer. In theory, that would allow you to explicitly pair the child and parent relationships. However, in FNH 2.1 there is a bug, and the override callback is never called. (<a href="https://github.com/jagregory/fluent-nhibernate/blob/release-1.2/src/FluentNHibernate/PersistenceModel.cs#L43" rel="noreferrer">The callback value is captured before it can be set by the method</a>).</p> <p>As a work around, you can disable all validation in FNH. There are <a href="https://github.com/jagregory/fluent-nhibernate/blob/release-1.2/src/FluentNHibernate/Visitors/ValidationVisitor.cs" rel="noreferrer">only two validations</a>. First, that both sides of a relationship don't have <code>.Inverse()</code>. Second, that an Id is mapped on each entity. The cleanest way I have found to disable validation is:</p> <pre><code>.Mappings(m =&gt; { var persistenceModel = new PersistenceModel() { ValidationEnabled = false }; m.UsePersistenceModel(persistenceModel) .FluentMappings.AddFromAssemblyOf&lt;Category&gt;(); }) </code></pre> <p>This approach allows you to disable validation but still use the full expressiveness of the <code>FluentMappings</code> configuration.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload