Radgrid is empty with llblgenprodatasource2, using session

Posts   
 
    
dotprof
User
Posts: 20
Joined: 19-Feb-2010
# Posted on: 02-Dec-2011 06:34:40   

Hello, I am trying to archive the following: Attach a Telerik Radgrid to a LLBLGenProDatasource2, then allow for the radgrid standard filtering and sorting without (extra) calls to the database. The grid does not require any update/delete/create so I only require a single fetch to the database.

I tried to archieve this putting a EntityCollection in Session and wireup the PerformSelect.

On the first hit (Page is Not Postback) the getData method is executed and the list in Session is loaded with data. However in the same call, in the PerformSelect method the session list is empty again, causing an empty grid.

I use the following code:

ascx user control:

  <llblgenpro:LLBLGenProDataSource2 ID="LLBLGUserdata" runat="server" 
            DataContainerType="EntityCollection" LivePersistence="false" 
        onperformselect="LLBLGUserdata_PerformSelect" SortingMode="ClientSide"   >
        </llblgenpro:LLBLGenProDataSource2>
  private EntityCollection<UserEntity> userList
        {
            get
            {
                if (Session["userList"] != null) return (EntityCollection<UserEntity>)Session["userList"];
                return null;
            }
            set
            {
                Session["userList"] = value;

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) getData();
            else
            {
                LLBLGUserdata.AdapterTypeName = "Dotprof.Reunie.Datalayer.DatabaseSpecific.DataAccessAdapter, Dotprof.Reunie.DatalayerDBSpecific";
                LLBLGUserdata.EntityFactoryTypeName = "Dotprof.Reunie.Datalayer.FactoryClasses.UserEntityFactory, Dotprof.Reunie.Datalayer";
                LLBLGUserdata.EntityCollection = userList;
                LLBLGUserdata.DataBind();

            }

        }

            protected void getData()
        {
            EntityCollection<UserEntity> usercollection = new EntityCollection<UserEntity>();
            using (DataAccessAdapter ds = new DataAccessAdapter())
            {
                IPrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.UserEntity);
                RelationPredicateBucket filter = new RelationPredicateBucket();
                filter.PredicateExpression.Add(UserFields.PortalId == currentPortal.PortalId);
                filter.PredicateExpression.AddWithAnd(UserFields.UserIsActive == true);
                filter.PredicateExpression.AddWithAnd(UserFields.UserIsDeleted == false);
                ds.FetchEntityCollection(usercollection, filter, prefetch);
            }
            userList = usercollection;
            LLBLGUserdata.AdapterTypeName = "Dotprof.Reunie.Datalayer.DatabaseSpecific.DataAccessAdapter, Dotprof.Reunie.DatalayerDBSpecific";
            LLBLGUserdata.EntityFactoryTypeName = "Dotprof.Reunie.Datalayer.FactoryClasses.UserEntityFactory, Dotprof.Reunie.Datalayer";
            LLBLGUserdata.EntityCollection = usercollection;
            LLBLGUserdata.DataBind();
        }

    
        protected void LLBLGUserdata_PerformSelect(object sender, PerformSelectEventArgs2 e)
        {
          e.ContainedCollection.AddRange(userList);

        }
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Dec-2011 07:09:07   

You should evaluate the order in which the actions are performed. It could be that when the PerformSelect is triggered by the grid, the getData isn't finished yet. This is not an LLBLGen problem. Anyway you may consider to move your getData call into the PerformSelect (only for !IsPostback), that should make the trick.

David Elizondo | LLBLGen Support Team
dotprof
User
Posts: 20
Joined: 19-Feb-2010
# Posted on: 02-Dec-2011 08:33:24   

Thanks Daelmo,

Quick response, it solved the problem partly. The order of events is correct hoewever, I see the userList setter being called by the getData method and filled with data, then the PerFormSelect is called and the userList is empty, the setter has not been called in between the two events (page load, and PerformSelect).

However I moved the getData to the datasource event, and I get an error. (I use LLBlGenPro version 3.1 )


[ArgumentException: c isn't of the right type]
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2`1.SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2.AddRange(IEntityCollection2 c) +159

Even though I added a cast to IEntityCollection2: In immediate window the cast is valid and returns a collection of dataobjects.

 protected void LLBLGUserdata_PerformSelect(object sender, PerformSelectEventArgs2 e)
        {
            if (!Page.IsPostBack) getData();
             e.ContainedCollection.AddRange((IEntityCollection2)userList);

        }
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 02-Dec-2011 09:34:22   

Why are you setting the EntityFactoryTypeName in code and not in the ASPX? Try to set it in the ASPX and see if this solves the problem.

dotprof
User
Posts: 20
Joined: 19-Feb-2010
# Posted on: 02-Dec-2011 10:22:32   

Hello Walaa, I moved the configuration to the ascx file (and removed in from the code behind):


  <llblgenpro:LLBLGenProDataSource2 ID="LLBLGUserdata" runat="server" 
            DataContainerType="EntityCollection" LivePersistence="false" CacheLocation="None" 
        onperformselect="LLBLGUserdata_PerformSelect" SortingMode="ClientSide" 
        AdapterTypeName="Dotprof.Reunie.Datalayer.DatabaseSpecific.DataAccessAdapter, Dotprof.Reunie.DatalayerDBSpecific" 
        EntityFactoryTypeName ="Dotprof.Reunie.Datalayer.FactoryClasses.UserEntityFactory, Dotprof.Reunie.Datalayer"  >
        </llblgenpro:LLBLGenProDataSource2>

This is causing the same error as mentioned before "c isn't the right type...." If I replace the line:


e.ContainedCollection.AddRange(userList as IEntityCollection2 );

with the following it works.

   foreach (UserEntity item in userList)
            {
                e.ContainedCollection.Add(item);
            }

It is not that neat to have to iterate the collection, so problem solved hoewever if you have a suggestion why the cast is not accepted ?.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 02-Dec-2011 10:41:00