How to use the LLBLGenProDataSource2 programmatically

Posts   
 
    
dotprof
User
Posts: 20
Joined: 19-Feb-2010
# Posted on: 09-Mar-2011 10:26:03   

Hello, Using the LLBLGenPro Datasource (LLBLGenProDataSource2) programmatically in an ASP.NET application can be done in certain scenario's. However how can this be done if the data collection is already available from an earlier action in the session or cache store.

Use object with sorting and filtering in program code:



            LLBLGenProAlbum.AdapterTypeName = "Datalayer.DatabaseSpecific.DataAccessAdapter, DatalayerDBSpecific";
            LLBLGenProAlbum.EntityFactoryTypeName = "Datalayer.FactoryClasses.PhotoAlbumEntityFactory, Datalayer";
            LLBLGenProAlbum.SorterToUse = new SortExpression(PhotoAlbumFields.DisplayOrder | SortOperator.Ascending);
            LLBLGenProAlbum.CacheLocation = DataSourceCacheLocation.None;
            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.PredicateExpression.Add(PhotoAlbumFields.PortalId == currentPortal.PortalId);
            LLBLGenProAlbum.FilterToUse = bucket;   
            LLBLGenProAlbum.DataBind();

Problem, if I want only to use an entitycollection, already sorted and filtered and stored in session in the following way, see codeblock below, then all records are still retrieved because the LLBlgen objectdatasource does require the EntityFactoryTypeName and this setting causes the retrieval of all records. The EntityCollection property is ignored.



            LLBLGenProAlbum.AdapterTypeName = "Datalayer.DatabaseSpecific.DataAccessAdapter, DatalayerDBSpecific";
            LLBLGenProAlbum.EntityFactoryTypeName = "Datalayer.FactoryClasses.PhotoAlbumEntityFactory, Datalayer";
            LLBLGenProAlbum.EntityCollection = (EntityCollection<PhotoAlbumEntity>)Session["Albumlist"]; 
            LLBLGenProAlbum.DataBind();

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Mar-2011 10:30:54   

You should set the LivePersistence property to False. And then handle the Perform_Select event to set the EntityCollection.

dotprof
User
Posts: 20
Joined: 19-Feb-2010
# Posted on: 09-Mar-2011 16:09:28   

Walaa wrote:

You should set the LivePersistence property to False. And then handle the Perform_Select event to set the EntityCollection.

Thanks for the advise, I found the following in the documentation, (should have red that first wink ):


protected void orderDS_PerformSelect(object sender, PerformSelectEventArgs2 e)
    {
        // fetch all orders which are in the selected page using the filter passed in
        // via the PerformSelectEventArgs2 object. 
        using(DataAccessAdapter adapter = new DataAccessAdapter())
        {
            adapter.FetchEntityCollection(e.ContainedCollection, e.Filter,
                    e.MaxNumberOfItemsToReturn, e.Sorter, e.PrefetchPath, 
                    e.PageNumber, e.PageSize);
        }
    }



Problem, I assumed I could replace the innerbody of the method with a assigment using the session variable. However, on compile I get the following error: Property or indexer 'SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2.ContainedCollection' cannot be assigned to -- it is read only. When I use the following body in the PerformSelect method:


e.ContainedCollection =albumlist;

The albumlist is a private property that keeps a collection in the session state with the following signature:


  private EntityCollection<PhotoAlbumEntity> albumlist

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Mar-2011 18:01:49   

Try using the following:

 e.ContainedCollection.AddRange(albumlist);
dotprof
User
Posts: 20
Joined: 19-Feb-2010
# Posted on: 10-Mar-2011 05:56:29   

Walaa wrote:

Try using the following:

 e.ContainedCollection.AddRange(albumlist);

Quick support, thanks Walaa, that has solved this question.