Note that there are some explanatory texts on larger screens.

plurals
  1. PODapper - using multimapping with split points other than Id
    primarykey
    data
    text
    <p>I know this is similar to <a href="https://stackoverflow.com/questions/7472088/correct-use-of-multimapping-in-dapper">Correct use of Multimapping in Dapper</a>, but I think it's slightly different. </p> <p>I have the following POCO structure:</p> <pre><code>public class Customer { public int customerkey { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string EmailAddress { get; set; } public List&lt;Invoice&gt; Invoices { get; set; } public int statekey { get; set; } public State State { get; set; } public Customer() { this.Invoices = new List&lt;Invoice&gt;(); } } public class Invoice { public int customerinvoicekey { get; set; } public int customerkey { get; set; } public int Number { get; set; } public string Description { get; set; } public int Total { get; set; } public int statuskey { get; set; } public State State { get; set; } } public class State { public int statekey { get; set; } public string Description { get; set; } } </code></pre> <p>I am trying to map this using Dapper and I'm not using Id for my split points. I can get it to work if I double up the keys, but I'm not sure why I have to do that. </p> <p>Why does this work:</p> <pre><code>const string commandText = @"SELECT A.customerkey, A.FirstName, A.LastName, A.EmailAddress, A.statuskey, C.statuskey, C.Description, B.customerinvoicekey, B.customerkey, B.Number, B.Description, B.Total, B.statuskey, D.statuskey, D.Description FROM Web.TestCustomers2 A INNER JOIN Web.TestCustomerInvoices2 B ON A.customerkey = B.customerkey INNER JOIN Web.TestStatus2 C ON A.statuskey = C.statuskey INNER JOIN Web.TestStatus2 D ON B.statuskey = D.statuskey ORDER BY A.customerkey"; var customers = new List&lt;Customer&gt;(); Customer currentCustomer = null; db.Connection.Query&lt;Customer, State, Invoice, State, Customer&gt;(commandText, (customer, customerstate, invoice, invoicestate) =&gt; { if (currentCustomer == null || currentCustomer.customerkey != customer.customerkey) { customers.Add(customer); currentCustomer = customer; } invoice.State = invoicestate; currentCustomer.Invoices.Add(invoice); currentCustomer.State = customerstate; return currentCustomer; }, splitOn: "statuskey,customerinvoicekey,statuskey"); </code></pre> <p>But this does not work (leaving out the select of statuskey in A and B):</p> <pre><code>const string commandText = @"SELECT A.customerkey, A.FirstName, A.LastName, A.EmailAddress, C.statuskey, C.Description, B.customerinvoicekey, B.customerkey, B.Number, B.Description, B.Total, D.statuskey, D.Description FROM Web.TestCustomers2 A INNER JOIN Web.TestCustomerInvoices2 B ON A.customerkey = B.customerkey INNER JOIN Web.TestStatus2 C ON A.statuskey = C.statuskey INNER JOIN Web.TestStatus2 D ON B.statuskey = D.statuskey ORDER BY A.customerkey"; var customers = new List&lt;Customer&gt;(); Customer currentCustomer = null; db.Connection.Query&lt;Customer, State, Invoice, State, Customer&gt;(commandText, (customer, customerstate, invoice, invoicestate) =&gt; { if (currentCustomer == null || currentCustomer.customerkey != customer.customerkey) { customers.Add(customer); currentCustomer = customer; } invoice.State = invoicestate; currentCustomer.Invoices.Add(invoice); currentCustomer.State = customerstate; return currentCustomer; }, splitOn: "statuskey,customerinvoicekey,statuskey"); </code></pre>
    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.
 

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