Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>I won't anyhow discuss the correctness of this approach, just try to answer.</em> What you are trying to do: <strong>should</strong> work. I've checked the correctness of the formula in a test scenario. So, yes formula could be used exactly this way.</p> <p>But because it is not working, I would a bit guess. Let's start with SQL generated in my test case, which is working.</p> <pre><code>SELECT this_.ParentId as ParentId3_0_ , (SELECT TOP 1 Child.ChildId FROM Child WHERE Child.ParentId = this_.ParentId) as formula1_0_ FROM Parent this_ </code></pre> <h2>Possible issues</h2> <p>I see two possible issues</p> <h3>1. Different Child ID column names</h3> <p>First of all in your snippet:</p> <pre><code>References&lt;ChildEntity&gt;(x =&gt; x.Child).Formula( @"( SELECT TOP 1 ChildTable.ChildId FROM ChildTable WHERE ChildTable.ParentId = ParentId )" </code></pre> <p>is column name of child primary key: <strong><code>ChildId</code></strong> while in SQL snippet is the <strong><code>ChildEntity_id</code></strong>:</p> <pre><code>SELECT this_.ParentId, this_.ChildEntity_id FROM ParentTable this_ </code></pre> <h3>2. SQL Snippet does not match</h3> <p>Secondly, you mentioned that the (SQL Statement just above) is what was generated. But it is more like a statement of this mapping:</p> <pre><code>References&lt;ChildEntity&gt;(x =&gt; x.Child).Column("ChildEntity_id") </code></pre> <p>So couldn't be there some older/other mapping, which is in fact used?</p> <p>SUMMARY I wanted to say, that this way of mapping is working. So you are on the correct track, but <em>the devil is hidden in details</em> ;)</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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