Projecting Stored Procedure resultset onto custom collection

Posts   
 
    
Waveslam
User
Posts: 18
Joined: 20-Nov-2006
# Posted on: 27-Feb-2007 03:37:32   

Hi I am using LLBLGen Pro v2.0, Self Servicing, C# .Net 2.0. I have a stored proc that returns a resultset that I want to project onto a List<> collection of custom objects (since it doesn't match any of my existing Entity objects so I can use a generated EntityCollection).

I am following the documentation in Using the Generated Code -> SelfServicing -> Fetching DataReaders and projections. In the section "Projecting Dynamic List resultset onto custom classes" it describes almost exactly what I want to do, but I dont understand the example code. Right at the bottom of the example, the code is:

// perform the fetch combined with the projection.
TypedListDAO dao = new TypedListDAO();
dao.GetAsProjection( valueProjectors, projector, null, fields, null, null, 0, null, true );

I am assuming that this piece of code is meant to be calling the same stored proc "pr_CustomersAndOrdersOnCountry" that is referenced in the preceding section "Projecting Stored Procedure resultset onto entity collection". If so, how does this work, since there is no mention at all of the stored proc in this piece of example code??

It may be that I am missing the point, in which case can you please post me a simple example of how to call a stored proc and map the returned resultset onto a collection of custom classes?

Thanks heaps in advance Cheers Brett

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 27-Feb-2007 05:12:39   

I believe you would do something like this.


            using (IRetrievalQuery query = RetrievalProcedures.GetCustomersAndOrdersOnCountryCallAsQuery("Germany"))
            {
                TypedListDAO dao = new TypedListDAO();
                using (IDataReader reader = dao.GetAsDataReader(null, query, CommandBehavior.CloseConnection))
                {
                    // first resultset: Customers.
                    List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
                    valueProjectors.Add(new DataValueProjector("City", 0, typeof(string)));
                    valueProjectors.Add(new DataValueProjector("CompanyName", 1, typeof(string)));
                    valueProjectors.Add(new DataValueProjector("CustomerID", 2, typeof(string)));
                    valueProjectors.Add(new DataValueProjector("Country", 3, typeof(string)));

                    DataProjectorToCustomClass<CustomCustomer> projector =
                new DataProjectorToCustomClass<CustomCustomer>(customClasses);                  
dao.GetAsProjection(valueProjectors, projector, reader);

                }
            }