Note that there are some explanatory texts on larger screens.

plurals
  1. PO(Fluent) NHibernate: Map field from separate table into object
    primarykey
    data
    text
    <p>I'm currently trying to get (Fluent)NHibernate to map an object to our legacy database schema. There are three tables involved. </p> <ul> <li>Table a contains most information of the actual object I need to retrieve</li> <li>Table b is a table which connects table a with table c</li> <li>Table c has one additional field I need for the object</li> </ul> <p>An SQL query to retrieve the information looks like this:</p> <pre><code>SELECT z.ID, z.ZANR, e.TDTEXT FROM PUB.table_a z JOIN PUB.table_b t ON (t.TDKEY = 602) JOIN PUB.table_c e ON (e.ID = t.ID AND e.TDNR = z.ZANR) WHERE z.ZANR = 1; </code></pre> <p>The main problem is how to specify these two join conditions in the mapping.</p> <p>Entity for table a looks like this:</p> <pre><code>public class EntityA { public virtual long Id { get; set; } public virtual int Number { get; set; } public virtual string Name { get; set; } } </code></pre> <p>Name should map to the column table_c.TDTEXT.</p> <p>The mapping I have so far is this:</p> <pre><code>public class EntityAMap : ClassMap&lt;EntityA&gt; { public EntityAMap() { Table("PUB.table_a"); Id(x =&gt; x.Id).Column("ID"); Map(x =&gt; x.Number).Column("ZANR"); } } </code></pre> <p>I tried to map the first join with the same strategy as in <a href="https://stackoverflow.com/questions/1241005/how-to-join-table-in-fluent-nhibernate">How to join table in fluent nhibernate</a>, however this will not work, because I do not have a direct reference from table_a to table_b, the only thing connecting them is the constant number 602 (see SQL-query above).</p> <p>I didn't find a way to specify that constant in the mapping somehow.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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