0
votes

I have a series of entities that I need to return to a caller. In some instances, they will want a Class A, in some a Class B, and in some both class A and B. The data are related, all from one table and there are a decent number of columns. The current code calls A, maps it to C.ClassOfA, calls B and maps it to ClassOfB. I can undo this mess of course, but I would like to return A and B as C with one call, but I'm struggling with Dapper (may be because this can't be done). I know if A references B I can return all using multi-mapping, but that's not the case. Also, Oracle database (which is not my strongest suit) if that matters. Suppose my two types are:

class A
  int InventoryOnHand {get;set;}
  int ProjectedSales {get;set;}
class B
  int ExpectedReturns{get;set;}
  int ProjectedProduction{get;set;}

class C
  A ClassOfA{get;set;}
  B ClassOfB{get;set;}

I can build the query I'm using dynamically and can return each type but I can't figure out how to map C such that the query that returns both A and B maps to C. I instead. Is this possible?

TIA

1

1 Answers

0
votes

If I understand well, you want to return objects of Class C which contains objects of ClassA/B. Ie nested classes within your ClassC.

Have you considered looking at Slapper: https://github.com/SlapperAutoMapper/Slapper.AutoMapper

which will map dapper data back to your classes?

The oracle sql would look something like the below and you would alias the selected columns so that they map/correspond to the property names on you classA/classB:

select a.value1 as ClassOfA_InventoryOnHand, 
   a.ProjectedSales as ClassOfA_ProjectedSales, 
   b.ExpectedReturns as ClassOfB_ExpectedReturns, 
from a, b