Thanks everybody for all your help! I've been able to create a generic method to convert a Stored Procedure to a collection:
/// <summary>
/// Gets the resultset of a Stored Procedure and returns it as a Collection.
/// </summary>
/// <typeparam name="EntityObject">Entities which the collection will be filled with.</typeparam>
/// <typeparam name="EntityCollection">The collection which must be returned.</typeparam>
/// <param name="query">The Stored Procedure as an IRetrievalQuery.</param>
/// <param name="transactionManager">If the sp is part of a transaction, put the Transaction here.</param>
/// <returns>A filled collection.</returns>
public EntityCollection ConvertStoredProcedureToCollection<EntityObject, EntityCollection>(IRetrievalQuery query, Transaction transactionManager)
where EntityObject : EntityBase, new()
where EntityCollection : EntityCollectionBase<EntityObject>, new()
{
//Create new instances of the EntityObject and EntityCollection.
EntityObject entityObject = new EntityObject();
EntityCollection entityCollection = new EntityCollection();
//Get all the Fields of the EntityObject. These fields are necessary for fetching all the data from the resultset.
IEntityFields entityFields = entityObject.Fields;
using (query)
{
//Get the resultset of the Stored Procedure as an IDataReader.
TypedListDAO dao = new TypedListDAO();
using (IDataReader reader = dao.GetAsDataReader(transactionManager, query, CommandBehavior.CloseConnection))
{
//Create a new instance of List<IDataValueProjector>. In this the values which will be fetched will be stored.
List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>(entityFields.Count);
foreach (EntityField entityField in entityFields)
{
//Put each entityField in List<IDataValueProjector>.
valueProjectors.Add(new DataValueProjector(entityField.Alias, entityField.FieldIndex, entityField.DataType));
}
//Create the projector and fill the collection.
DataProjectorToIEntityCollection projector = new DataProjectorToIEntityCollection(entityCollection);
dao.GetAsProjection(valueProjectors, projector, reader);
reader.Close();
}
}
return entityCollection;
}
Now if you want to convert a Stored Procedure to a collection all you have to do is:
UmbracoProductCollection umbracoProductCollection = ConvertStoredProcedureToCollection<UmbracoProductEntity, UmbracoProductCollection>(RetrievalProcedures.GetSpDigiGetRecursiveUmbracoProductsCallAsQuery(productGroupCode), null);
If people like this code it can be added to DbUtils class of LLBLGen.