Note that there are some explanatory texts on larger screens.

plurals
  1. POdapper PropInfo Setter for inherited EntitySet from abstract class reference is null
    primarykey
    data
    text
    <p>I am trying to replace a nasty LINQ 2 SQL hit with some dapper queries to improve performanace. In doing so I have to weave a bunch of different objects together in order to create the big object required to hold all the information I need for ASN information. </p> <p>The current problem I am having is with an abstract class Orders, this class is implemented by two seperate classes AutionOrder and MerchantOrder using a discriminator property. </p> <p>Since I cannot use dapper to create a object that is an abstract class I am instead using one of the public classes. however when it goes to build the object it is failing inside of <code>GetSettableProps</code> it is finding the proper <code>DeclaringType</code> but the <code>GetProperty</code> method is returning null when it is looking for an property that is <code>internal</code> or is an <code>EntitySet</code>. I've tried to hack around it using <code>t.BaseType.GetProperty</code> as well as <code>p.GetAccessors().First().GetBaseDefinition().DeclaringType.GetProperty(p.Name).GetSetMethod(true)</code> with no success. </p> <p>dummy objects:</p> <blockquote> <p>Order</p> <blockquote> <p>OrderID, Name, Address, RowVersion(internal), Shipments(EntitySet),OrderDetails(EntitySet), Customer(EntityRef)</p> </blockquote> <p>Shipment</p> <blockquote> <p>ShipmentID, OrderID, TrackingNumber</p> </blockquote> <p>OrderDetails</p> <blockquote> <p>OrderDetailID, OrderID, Product, QTY, Price</p> </blockquote> <p>Customer</p> <blockquote> <p>CustomerID, Name, </p> </blockquote> </blockquote> <p>For this particular SQL hit I am trying to grab some of the 1 to 1 relationship mappings I need. </p> <blockquote> <p>SELECT o.* from Orders as o left join Customers as c on o.CustomerID = c.CustomerID where o.OrderID in (1,2,3);</p> </blockquote> <p>This is what I am using to utilize dapper and let it do it's magic:</p> <pre><code>using (var connection = new SqlConnection(_ConnectionString)) { connection.Open(); results = connection.Query&lt;MerchantOrder, MerchantCustomer, MerchantOrder&gt;(sql.ToString(), (o, c) =&gt; { o.Customer = c; return o; }, splitOn: "CustomerID"); } </code></pre> <p>If I change Order to be a public class this problem goes away though, but this is not a desired side-effect. It is failing when trying to set the propInfo for RowVersion - switching this to public instead of internal solved this problem - although not desired. But then it fails when it is trying to create the Shipments objects for Order. Again none of this is an issue when Order is a public class. </p> <p>Also I am doing separate queries to pull in Many to one relationships such as Shipments to Orders and OrderDetails to Orders and normalizing the results into a proper Order Object. MerchantOrder is pretty much an empty class with no real special logic. The discriminating different here is just how we end up finding the CustomerID which is abstracted away prior to the actual SQL hit anyway. </p> <p>Also I am using the latest version of dapper as of 12/20/2011. </p> <p>I really like dapper, but this problem is making my head asplode - so thanks for the help!</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