Stored procedure into a projection

Posts   
 
    
lsberman
User
Posts: 16
Joined: 22-Feb-2006
# Posted on: 08-Jun-2007 18:50:44   

Hi! I've been trying to do a projection from a stored proc but to no avail. The stored proc returns an arbitrary collection of fields, some of which are mapped on existing entities others of which exist only in the output of the stored procedure. Could you please give me a concrete example in C# of how to do this?

For this example assume the "GetInfoById" stored procedure would take an "Id" as an input and returns multiple rows of "Code" and a "Price".

Thank you....

lsberman
User
Posts: 16
Joined: 22-Feb-2006
# Posted on: 08-Jun-2007 19:06:04   

Never min! I figured it out:

using System; using System.Data; using System.Collections.Generic; using System.Text; using SD.LLBLGen.Pro.ORMSupportClasses; using LLBLGenTest.CollectionClasses; using LLBLGenTest.EntityClasses; using LLBLGenTest.FactoryClasses; using LLBLGenTest.HelperClasses; using LLBLGenTest.RelationClasses; using LLBLGenTest.DaoClasses; using LLBLGenTest.StoredProcedureCallerClasses;

namespace DALTest { class Program { public class MasterChild { private string code; private DateTime addedOn; private int units; private decimal price;

        public string Code
        {
            get { return code; }
            set { code = value; }
        }

        public DateTime AddedOn
        {
            get { return addedOn; }
            set { addedOn = value; }
        }

        public int Units
        {
            get { return units; }
            set { units = value; }
        }

        public decimal Price
        {
            get { return price; }
            set { price = value; }
        }
    }

    static void Main(string[] args)
    {
        int MASTERID = 1;

        List<MasterChild> results = new List<MasterChild>();

        using (IRetrievalQuery query = RetrievalProcedures.
            GetGetChildrenByMasterIdCallAsQuery(MASTERID))
        {
            TypedListDAO dao = new TypedListDAO();

            using (IDataReader reader = 
                dao.GetAsDataReader(null, query, CommandBehavior.CloseConnection))
            {
                List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
                valueProjectors.Add(new DataValueProjector("Code", 0, typeof(string)));
                valueProjectors.Add(new DataValueProjector("AddedOn", 1, typeof(DateTime)));
                valueProjectors.Add(new DataValueProjector("Units", 2, typeof(int)));
                valueProjectors.Add(new DataValueProjector("Price", 3, typeof(decimal)));

                DataProjectorToCustomClass<MasterChild> projector =
                    new DataProjectorToCustomClass<MasterChild>(results);
                        dao.GetAsProjection(valueProjectors, projector, reader);
            }
        }
    }
}

}