Note that there are some explanatory texts on larger screens.

plurals
  1. POPersistenceSpecification and inverse
    text
    copied!<p>I've already posted this in the Fluent NH group a long time ago, but didn't get any answers until today. SO, here's the problem: I've got a one-to-many relationship defined and the one side has the inverse flag set. the mapping code looks something like this:</p> <pre><code>public class MapeamentoReceita : ClassMap&lt;Receita&gt; { public MapeamentoReceita() { Table("Receitas"); Not.LazyLoad(); Id(rec =&gt; rec.Id, "IdReceita") .GeneratedBy .HiLo("TabelaHilo", "ProximoHi", "1000", "Tabela='receitas'") .Default(0); Version(rec =&gt; rec.Versao); //other props go here HasMany(rec =&gt; rec.Imagens) .Access.CamelCaseField((Prefix.Underscore)) .AsBag() .Cascade.All() .KeyColumn("IdReceita") .Not.LazyLoad() .Inverse(); } } </code></pre> <p>Now, Imagem's mapping looks like this:</p> <pre><code> public class MapeamentoImagem : ClassMap&lt;Imagem&gt; { public MapeamentoImagem() { Table("Imagens"); Not.LazyLoad(); Id(img =&gt; img.Id, "IdImagem") .GeneratedBy .HiLo("TabelaHiLo", "ProximoHi", "1000", "Tabela='imagens'") .Default(0); Map(img =&gt; img.Bytes) .CustomSqlType("image") .CustomType&lt;Byte[]&gt;() .LazyLoad() .Length(2000000000) .Not.Nullable() .Not.Update(); References(img =&gt; img.Receita) .Column("IdReceita") .Cascade.None(); } } </code></pre> <p>And here's the code that tests the persistence of these classes:</p> <pre><code> new PersistenceSpecification&lt;Receita&gt;(sess) .CheckList(rec =&gt; rec.Imagens, _imagens, (receita, imagem) =&gt; receita.AdicionaImagem(imagem)) .VerifyTheMappings(); </code></pre> <p>Even though Inverse is "on", PersistenceSpecification tries to insert Imagem before inserting Receita. Since IdReceita is foreign key configured not to accept null, I end up with an exception. I've tried writing "real world code" that uses receita and it works (I've turned on SQL and I can see that in this case, Receita is inserted before Imagem as it should be).</p> <p>Since nobody answered this question on FH group, I was wondering if someone can please confirm that this PersistenceSpecification behavior is a bug.</p> <p>thanks.</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