How to implement paging on llbgenpro datasource

Posts   
 
    
linzx
User
Posts: 64
Joined: 28-Dec-2010
# Posted on: 24-May-2011 09:11:02   

Hi

I want to got a demo which can show how to page on llblgenpro datasource.

I used llblgenpro datasource under "LivePersistence=false",

<llblgenpro:LLBLGenProDataSource2 ID="RegulationListDataSource" runat="server" CacheLocation="Session" AdapterTypeName="Enhesa.BusinessObjects.Adapter.DatabaseSpecific.DataAccessAdapter, Enhesa.BusinessObjects.Adapter" DataContainerType="EntityCollection" EntityFactoryTypeName="Enhesa.BusinessObjects.Adapter.FactoryClasses.RegulationTextEntityFactory, Enhesa.BusinessObjects.Adapter" LivePersistence="false" OnPerformSelect="RegulationListDataSource_PerformSelect" OnPerformWork="RegulationListDataSource_PerformWork" EnablePaging="true" OnPerformGetDbCount="RegulationListDataSource_PerformGetDbCount"> </llblgenpro:LLBLGenProDataSource2>

by the way I dodn't know how to use the OnPerformGetDbCount event.

Best regards Ricky

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-May-2011 12:08:13   

There is a full code example in the docs, that should show you the way.

Here you are: Example using Perform Event handlers

linzx
User
Posts: 64
Joined: 28-Dec-2010
# Posted on: 26-May-2011 08:18:20   

Walaa wrote:

There is a full code example in the docs, that should show you the way.

Here you are: Example using Perform Event handlers

The demo is more simple for me. I read associated document before and have implement this simple demo. But it cannot use in our project. Our porject use linq to llblgenpro rather than the approach of llblgenpro.

Such as :

protected void RegulationListDataSource_PerformSelect(object sender, PerformSelectEventArgs2 e) {

         presenter = new Presenter(this);
         RegulationListDataSource.EntityCollection = presenter.LoadRegulationListDataSource().AsEntityCollection;

        RegulationListDataSource.Refetch = false;
    }

public IQueryable<RegulationTextEntity> LoadRegulationsScalarDataSource(pageNumber) { var q = RawQuery(); q = FilterBy(q); q = FilterByStatus(q); q = ExcludeFields(q); q = PrefetchPaths(q); //temporarily put into RawQuery until more info is available on the bug return q; }

private IQueryable<RegulationTextEntity> RawQuery() { return linqMetaData.RegulationText; }

    private IQueryable<RegulationTextEntity> PrefetchPaths(IQueryable<RegulationTextEntity> q)
    {
        //BUG This is a very weird bug. The idClient and FacilityCode field variables get lost in the Linq Expression evaluation. I have to set new ones to use, but only in this PrefetchPaths method
        var isArrseparatedRegions = CheckIsArrseparatedRegions();
        int idClient2 = idClient;
        string facilityCode2 = facilityCode;
        string countryCode2 = countryCode;
        string regionCode2 = regionCode;
        var serviceCode2 = serviceCode;
        var headingMainCode2 = headingMainCode;
        return
            q.WithPath(
                a =>
                a.Prefetch<RegulationBaseEntity>(b => b.Regulation).SubPath(
                    c =>
                    c.Prefetch<AnswerRegulationEntity>(d => d.AnswerRegulation).FilterOn(
                        j =>
                        j.IDClient == idClient2 &&
                        j.FacilityCode.Equals(facilityCode2, StringComparison.InvariantCultureIgnoreCase))
                        .Prefetch<RegulationHeadingEntity>(h => h.RegulationHeading).FilterOn(
                            e =>
                            ((headingMainCode2 != null && headingMainCode2 != string.Empty &&
                              headingMainCode2 != "Total" &&
                              e.HeadingCode.Substring(0, 2) == headingMainCode2) ||
                             !(e.HeadingCode.StartsWith("01") || e.HeadingCode.StartsWith("13") ||
                               e.HeadingCode.StartsWith("14") || e.HeadingCode.StartsWith("15"))) &&
                            e.Heading.HeadingSetCode.Any(
                                s =>
                                s.HeadingSet.ClientRegion.Any(
                                    r => r.IDClient == idClient2 && r.ServiceCode == serviceCode2)))
                        .Prefetch<RegulationQnEntity>(n => n.RegulationQn)
                        .Prefetch<QnBaseEntity>(k => k.QnCollectionViaRegulationQn).FilterOn(
                            e =>
                            e.Archived.Equals(false) &&
                            e.CountryCode.Equals(countryCode2, StringComparison.InvariantCultureIgnoreCase)
                            &&
                            ((!isArrseparatedRegions &&
                              e.RegionCode.Equals("_countrywide", StringComparison.InvariantCultureIgnoreCase)) ||
                             e.RegionCode.Equals(regionCode2, StringComparison.InvariantCultureIgnoreCase)) &&
                            !(e.HeadingCode.StartsWith("01") || e.HeadingCode.StartsWith("13") ||
                              e.HeadingCode.StartsWith("14") || e.HeadingCode.StartsWith("15"))).SubPath
                        (l => l.Prefetch<AnswerQnEntity>(m => m.AnswerQn).FilterOn(
                            j =>
                            j.IDClient == idClient2 &&
                            j.FacilityCode.Equals(facilityCode2, StringComparison.InvariantCultureIgnoreCase)))
                        .Prefetch<RegulationCountryRegionEntity>(e => e.RegulationCountryRegion)
                        .FilterOn(
                            r => r.CountryCode.Equals(countryCode2, StringComparison.InvariantCultureIgnoreCase)
                                 &&
                                 ((!isArrseparatedRegions &&
                                   r.RegionCode.Equals("_countrywide", StringComparison.InvariantCultureIgnoreCase)) ||
                                  r.RegionCode.Equals(regionCode2, StringComparison.InvariantCultureIgnoreCase))))
                );
    }

    private IQueryable<RegulationTextEntity> FilterBy(IQueryable<RegulationTextEntity> q)
    {
        var isArrseparatedRegions = CheckIsArrseparatedRegions();
        var headingText = linqMetaData.HeadingText.Where(h => h.LanguageCode == "en"
                                                              && (h.HeadingCode == "02"
                                                                  || h.HeadingCode == "03"
                                                                  || h.HeadingCode == "04"
                                                                  || h.HeadingCode == "05"
                                                                  || h.HeadingCode == "06"
                                                                  || h.HeadingCode == "07"
                                                                  || h.HeadingCode == "08"
                                                                  || h.HeadingCode == "09"
                                                                  || h.HeadingCode == "10"
                                                                  || h.HeadingCode == "11"
                                                                  || h.HeadingCode == "12"
                                                                 ));
        return
            q.Where(
                a =>
                ((!q.Any(n => n.LanguageCode == languageCode && n.RegID == a.RegID) && a.LanguageCode == "en") ||
                  a.LanguageCode == languageCode) && a.Regulation.Effective
                      && linqMetaData.ClientRegion.Any(e => e.IDClient == idClient && e.ServiceCode == serviceCode
                          && e.CountryCode == countryCode &&
                                                               ((!isArrseparatedRegions &&
                                                                 e.RegionCode.Equals("_countrywide",
                                                                                     StringComparison.
                                                                                         InvariantCultureIgnoreCase)) ||
                                                                e.RegionCode == regionCode
                                                               )
                         && e.Region.RegulationCountryRegion.Any(d => d.RegID == a.RegID)
                         && e.HeadingSet != null
                        && e.HeadingSet.HeadingSetCode.Any(
                            g => g.Heading.RegulationHeading.Any(h => h.RegID == a.RegID)
                          &&
                           linqMetaData.QryHeadingsExpandedTopLevel.Any(
                               f =>
                               f.ChildHeadingCode == g.HeadingCode &&
                               ((headingMainCode != null && headingMainCode != string.Empty &&
                                 headingMainCode != "Total")
                                    ? f.HeadingCode == headingMainCode
                                    : headingText.Count(n => n.HeadingCode == f.HeadingCode) > 0)
                               ))
                                     ));
    }

    private IQueryable<RegulationTextEntity> FilterByStatus(IQueryable<RegulationTextEntity> regulationTextEntities)
    {
        if (regulationsStatus == Consts.Repealed)
        {
            return
                regulationTextEntities.Where(
                    a => a.Regulation.Archived &&
                         a.Regulation.AnswerRegulation.Any(
                             b =>
                             b.FacilityCode == facilityCode && b.IDClient == idClient &&
                             b.Answer.Trim() == Consts.Yes));
        }
        regulationTextEntities = regulationTextEntities.Where(
            a => !a.Regulation.Archived);
        if (regulationsStatus == Consts.Applicable ||
            regulationsStatus == Consts.Relevant)
        {
            return
                regulationTextEntities.Where(
                    a =>
                    a.Regulation.AnswerRegulation.Any(
                        b =>
                        b.FacilityCode == facilityCode && b.IDClient == idClient &&
                        b.Answer.Trim() == Consts.Yes));
        }
        if (regulationsStatus == Consts.NoActiveRequirements)
        {
            return regulationTextEntities.Where(a => a.Regulation.RegulationQn.Count() == 0);
        }
        if (regulationsStatus == Consts.NotApplicable)
            return
                regulationTextEntities.Where(
                    a =>
                    a.Regulation.AnswerRegulation.Any(
                        b =>
                        b.FacilityCode == facilityCode && b.IDClient == idClient &&
                        b.Answer.Trim() == Consts.No));
        if (regulationsStatus == Consts.RequiresRevalidation ||
            regulationsStatus == Consts.ToBeRevalidated)
        {
            return
                regulationTextEntities.Where(
                    a =>
                    a.LastModifiedDate > linqMetaData.AnswerRegulation.Where(
                        r =>
                        r.FacilityCode == facilityCode && r.IDClient == idClient && r.RegID == a.RegID
                                             ).
                                             Select(s => s.AnswerLastModifiedDate).FirstOrDefault() ||
                    a.LastModifiedDate > linqMetaData.AnswerRegulation.Where(
                        r =>
                        r.FacilityCode == facilityCode && r.IDClient == idClient && r.RegID == a.RegID
                                             ).
                                             Select(s => s.CommentLastModifiedDate).FirstOrDefault());
        }
        if (regulationsStatus == Consts.Undetermined)
            return
                regulationTextEntities.Where(
                    a =>
                    a.Regulation.AnswerRegulation.Count(
                        b => b.FacilityCode == facilityCode && b.IDClient == idClient) == 0 ||
                    a.Regulation.AnswerRegulation.Any(
                        b => b.FacilityCode == facilityCode && b.IDClient == idClient &&
                             (b.Answer == null ||
                              b.Answer.Trim() == Consts.Unsure)));
        return regulationTextEntities;
    }

    private IQueryable<RegulationTextEntity> ExcludeFields(IQueryable<RegulationTextEntity> q)
    {
        return q.ExcludeFields(a => a.RegSummary, a => a.MainRequirements);
    }

So I want to know how to implement paging on Linq way here.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-May-2011 10:19:51   

That's a lot of code to look at.

Generally the idea is as follows:

  • The UI control passes paging parameters (pageNumber & pageSize) to the DataSource
  • In the PerformSelect event handler, you should make use of these parameters found in the PerformSelectEventArgs2.
  • Use these values in the Linq query to perform paging.
  • The Linq method for pagin is: .TakePage(pageNumber, pageSize);