Stored Procedures And TypedList

Posts   
 
    
Posts: 21
Joined: 07-Jul-2008
# Posted on: 30-Oct-2008 17:03:04   

**I Need return results of a Stored Procedure (EXEC SPGetProductsOfCategoryPaginationCompact 6)

Already Mapped this SP in LLBLGen Adapter Template **

My Facade Class :: (ErpProdutoCommand)


        public static EntityCollection<ErpProdutoStatusEntity> GetListByCategory(int categoryId, bool fetchAllNodes, int results)
        {
            EntityCollection<ErpProdutoStatusEntity> ret = new EntityCollection<ErpProdutoStatusEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                IRetrievalQuery queryResults = RetrievalProcedures.GetSpgetProductsOfCategoryCallAsQuery(categoryId);
                using (IDataReader reader = adapter.FetchDataReader(queryResults, CommandBehavior.CloseConnection))
                {
                    while (reader.Read())
                        ret.Add(ErpProdutoProxy.FetchFullProductStatus(reader));
                }
            }

            return ret;

I'm using this code to Fetch My Procedure (Class::ErpProdutoProxy)


        internal static ErpProdutoStatusEntity FetchFullProductStatus(IDataReader reader)
        {
            /*Required by Inner Join*/
            ErpProdutoEntity produto = ErpProdutoProxy.FetchProductRetrievalQuery(reader, 0);
            ErpMarcaEntity marca = ErpProdutoProxy.FetchMarcaRetrievalQuery(reader, 12);
            ErpProdutoStatusEntity produtoStatus = ErpProdutoProxy.FetchProductStatusRetrievalQuery(reader, 14);
            ErpStatusEntity status = ErpProdutoProxy.FetchStatusRetrievalQuery(reader, 22);
            /*Left Join*/
            VitrineProdutosFotosEntity produtoFoto = ErpProdutoProxy.FetchProductPhotoRetrievalQuery(reader, 24);
            VitrineProdutosComplementosEntity produtoComplementos = ErpProdutoProxy.FetchProductComplementsRetrievalQuery(reader, 27);

            produtoStatus.ErpProduto = produto;
            produtoStatus.ErpStatus = status;
            if (produtoComplementos != null)
                produtoStatus.VitrineProdutosComplementos = produtoComplementos;
            if (produtoFoto != null)
                produtoStatus.VitrineProdutosFotos.Add(produtoFoto);

            return produtoStatus;
        }

And this to any Entities: (Class::ErpProdutoProxy)


        internal static VitrineProdutosFotosEntity FetchProductPhotoRetrievalQuery(IDataReader reader, int initialIndex)
        {
            if (reader.IsDBNull(0 + initialIndex))
                return null;
            VitrineProdutosFotosEntity foto = new VitrineProdutosFotosEntity()
            {
                IdFoto = reader.GetInt32(0 + initialIndex),
                IdProduto = reader.GetInt32(0 + initialIndex),
                Foto = reader.GetValue(0 + initialIndex).ToString()
            };

            return foto;
        }

I want make this with a TypedList? Is Possible?

Posts: 21
Joined: 07-Jul-2008
# Posted on: 30-Oct-2008 17:11:30   

Oh... Sorry.

I'm Using: LLBLGen 2.6 Final .Net Framework 3.5 Adapter Mode

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 30-Oct-2008 19:12:22   

You can fetch it into a typed list through a projection to a datatable (as a typedlist is a datatable), by first designing the typedlist in the designer and then in your code using a projection from a stored procedure, as stated here (this is to an entity, but you can use a DataProjectorToDataTable projector instead to project to a datatable)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 21
Joined: 07-Jul-2008
# Posted on: 30-Oct-2008 19:49:20   

Thank you. I think it would be nice to implement a solution that.