Correct mapping of Dapper map objects / populations

I recently started evaluating Dapper as a potential replacement for EF, as I was not too happy with the SQL that was generated and needed more control over it. I have a question regarding matching a complex object in my domain model. Say I have an object called a provider. A provider can contain several properties of type IEnumerable, which should be accessible only through the parent provider object (i.e., aggregate root). I saw similar messages that were explained using the QueryMultiple method and the map extension, but wondered as if I wanted to write a method that could return the entire loaded object graph, if Dapper could do it in one fell swoop, or if it needed to be done with a piece . As an example, I can say that my object looked something like this:

public AggregateRoot
      {
           public int Id {get;set;}
           ...//simple properties
           public IEnumerable<Foo> Foos
           public IEnumerable<Bar> Bars
           public IEnumerable<FooBar> FooBars
           public SomeOtherEntity Entity
           ...
      }

Dapper?

+5
1

. sql return flat, . Query < > . , .

- :

var cnn =  sqlconnection();

var results = cnn.Query<AggregateRoot,Foo,Bars,FooBar,someOtherEntity,AggregateRoot>("sqlsomething"
                (ar,f,b,fb,soe)=>{
                    ar.Foo = f;
                    ar.Bars = b;
                    ar.FooBar = fb;
                    ar.someotherentity = soe;
                    return ar;

                },.....,spliton:"").FirstOrDefault();

, Query . SplitOn , . , .

:

select ID,fooid, foo1,foo2,BarName,barsomething,foobarid foobaritem1,foobaritem2 from blah

"ID, fooid, BarName, foobarid". , , .

, , , .

+7

All Articles