Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just ran a test that works fine: </p> <pre><code>var sql = "select cast(1 as decimal) ProductId, 'a' ProductName, 'x' AccountOpened, cast(1 as decimal) CustomerId, 'name' CustomerName"; var item = connection.Query&lt;ProductItem, Customer, ProductItem&gt;(sql, (p, c) =&gt; { p.Customer = c; return p; }, splitOn: "CustomerId").First(); item.Customer.CustomerId.IsEqualTo(1); </code></pre> <p>The splitOn param needs to be specified as the split point, it defaults to Id. If there are multiple split points, you will need to add them in a comma delimited list.</p> <p>Say your recordset looks like this: </p> <pre> ProductID | ProductName | AccountOpened | CustomerId | CustomerName --------------------------------------- ------------------------- </pre> <p>Dapper needs to know how to split the columns in this order into 2 objects. A cursory look shows that the Customer starts at the column <code>CustomerId</code>, hence <code>splitOn: CustomerId</code>.</p> <p>There is a <strong>big</strong> caveat here, if the column ordering in the underlying table is flipped for some reason:</p> <pre> ProductID | ProductName | AccountOpened | CustomerName | CustomerId --------------------------------------- ------------------------- </pre> <p><code>splitOn: CustomerId</code> will result in a null customer name. </p> <p>If you specify <code>CustomerId,CustomerName</code> as split points, dapper assumes you are trying to split up the result set into 3 objects. First starts at the beginning, second starts at <code>CustomerId</code>, third at <code>CustomerName</code>. </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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