Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Perhaps this is a recent fix in FluentNHibernate, but this works with FluentNH v1.2.0.712. I'm fairly confident that NHibernate with plain *.hbm.xml mappings has supported this type of mapping for years.</p> <p>This is the automapping override that worked for me:</p> <pre><code>mapping.HasMany(x =&gt; x.SupportedTransactionTypes) .Element("TransactionTypeId"); </code></pre> <p>...which results in this XML...</p> <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class xmlns="urn:nhibernate-mapping-2.2" name="so.Q2676867.PaymentMethod, so, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`PaymentMethod`"&gt; &lt;id access="backfield" name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="Id" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;bag name="SupportedTransactionTypes"&gt; &lt;key&gt; &lt;column name="PaymentMethod_id" /&gt; &lt;/key&gt; &lt;element type="so.Q2676867.TransactionType, so, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"&gt; &lt;column name="TransactionTypeId" /&gt; &lt;/element&gt; &lt;/bag&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>... and these tables:</p> <pre><code>create table [PaymentMethod] ( Id INT IDENTITY NOT NULL, primary key (Id) ) create table SupportedTransactionTypes ( PaymentMethod_id INT not null, TransactionTypeId INT null ) alter table SupportedTransactionTypes add constraint FK738E3751B597A1C foreign key (PaymentMethod_id) references [PaymentMethod] </code></pre> <p>... which is exactly what I would expect. Yay NHibernate!</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