TypedList sorting in LLBLGENPRO 2.0

Posts   
 
    
m@rius
User
Posts: 3
Joined: 31-Jan-2007
# Posted on: 31-Jan-2007 10:56:08   

I have just upgraded to version 2.1 and i my company we have decided not to use anymore PredicateFactory and SortClauseFactory due to large number of overloads. Because of that we've encountered some problems. One of them is sorting a TypedList without having to use SortClauseFactory. The thing is that in the TyedList we have each table with an alias and without SortClauseFactory in which we could specify the column name in the TypedList's FieldIndex, i cannot specify the alias properly.

With the help of the SQL Profiler I could see that each alias in the TypedList is generated with another name (for example alias "SOO" appears to be rewritten into "LPA_S1") and when adding an ORDER BY clause ,with the use of SortClause in which i can specify the alias of the column to be sorted after, the alias i have specified in the SortClause appears as it is and not changed into the rewrting of the alias of the same table in the TypedList.

Please help

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 31-Jan-2007 11:13:07   

m@rius wrote:

I have just upgraded to version 2.1 and i my company we have decided not to use anymore PredicateFactory and SortClauseFactory due to large number of overloads. Because of that we've encountered some problems. One of them is sorting a TypedList without having to use SortClauseFactory. The thing is that in the TyedList we have each table with an alias and without SortClauseFactory in which we could specify the column name in the TypedList's FieldIndex, i cannot specify the alias properly.

You mean, v2.0 wink (v2.1 is in development).

It's not that hard as it looks. You should use the <entityname>Fields classes. This example sorts the CompanyName field in the typedlist of the customer entity which is aliased in the typedlist as 'C'. SortExpression sorter = new SortExpression(); sorter.Add(CustomerFields.CompanyName.SetObjectAlias("C") | SortOperator.Ascending);

Could you post a code snippet so we can help you convert that to the new format, so you get an example how it's done? (if you're using VB.NET, please specify if you're using .NET 2.0 or .NET 1.x)

Frans Bouma | Lead developer LLBLGen Pro
m@rius
User
Posts: 3
Joined: 31-Jan-2007
# Posted on: 31-Jan-2007 11:47:07   

Yeah sorry 2.0.Using C# and ASP.NET 2.0. Ok that did'n work..here is the code with the problems: One method that returns the list for an ObjectDataSource in which we have :

SME_SupplierOrganisationTypedList ret = new SME_SupplierOrganisationTypedList(); ret.Columns.Add("PrimaryContact", typeof(string), "LastName + ', ' + FirstName"); IRelationPredicateBucket bucket = CreateBucketForSMESupplierOrganisationListTypedList(parameters, orgUnitId); ISortExpression sorter = CreateSorterForSMESupplierOrganisationListTypedList(sortField); int pageNumber = LlblHelper.GetPageNumber(rowIndex, pageSize); using (DataAccessAdapter dataAdapter = DataAdapterFactory.NewDataAdapter()) { dataAdapter.FetchTypedList(ret.GetFieldsInfo(), ret, bucket, 0, sorter, false, null, pageNumber, pageSize); }

and the CreateBucket method creates the filetring data in wich all the expressions are added like

ret.PredicateExpression.Add(new FieldCompareValuePredicate(CORE_SupplierOrganisationFields.IsDeleted, null, ComparisonOperator.Equal, 0, "SO"));

as you can see the aliases for the tables in the TypedList are specified. And the sorter method

    public static ISortExpression CreateSorterForSMESupplierOrganisationListTypedList(string sortField)
    {
        if (string.IsNullOrEmpty(sortField))
            sortField = "Name";

        SortOperator operatorToUse = LlblHelper.GetSortType(sortField);
        sortField = sortField.Split(' ')[0];

        ISortExpression sorter = new SortExpression();
        switch (sortField)
        {
            case "PrimaryContact": //full name of the supplier
                sorter.Add(UME_CustomerFields.LastName | operatorToUse);
                sorter.Add(UME_CustomerFields.FirstName | operatorToUse);
                break;
            case "Name": // SO name
                sorter.Add(CORE_SupplierOrganisationFields.Name.SetObjectAlias("SOPCC") | operatorToUse);
                break;
            case "DUNS":
                sorter.Add(CORE_SupplierOrganisationFields.DUNS | operatorToUse);
                break;
            case "CreatedOn":
                sorter.Add(CORE_SupplierOrganisationFields.CreatedOn | operatorToUse);
                break;
            default:
                throw new NotImplementedException();
        }
        return sorter;
    }

it is currently called to enter the Name case (modified according to you). With the profiler I get after dataAdapter.FetchTyedList() call the following:

SELECT [LPA_S1].[SupplierOrganisationID], [LPA_S1].[OrgUnitID], [LPA_S1].[Name], [LPA_S1].[DUNS], [LPA_S6].[CustomerID] AS [PrimaryContactID], [LPA_S6].[FirstName], [LPA_S6].[LastName], [LPA_S1].[CreatedOn] FROM (((((((( [dbo].[tbl_CORE_SupplierOrganisation] [LPA_S1]
INNER JOIN [dbo].[tbl_CORE_AddressBookXSupplierOrganisation] [LPA_A2] ON [LPA_S1].[SupplierOrganisationID]=[LPA_A2].[SupplierOrganisationID]) INNER JOIN [dbo].[tbl_AddressBooks] [LPA_A3] ON [LPA_A3].[AddressBookID]=[LPA_A2].[AddressBookID]) INNER JOIN [dbo].[tbl_OrgUnitAddressBook] [LPA_O4] ON [LPA_A3].[AddressBookID]=[LPA_O4].[AddressBookID]) LEFT JOIN [dbo].[tbl_CORE_SupplierOrganisationXCustomer] [LPA_S5] ON [LPA_S1].[SupplierOrganisationID]=[LPA_S5].[SupplierOrganisationID]) LEFT JOIN [dbo].[tbl_Customer] [LPA_S6] ON [LPA_S6].[CustomerID]=[LPA_S5].[CustomerID]) LEFT JOIN [dbo].[tbl_REG_CustomerRegistration] [LPA_C7] ON [LPA_S6].[CustomerID]=[LPA_C7].[CustomerID]) INNER JOIN [dbo].[tbl_CORE_SupplierOrganisationXCustomer] [LPA_S8] ON [LPA_S1].[SupplierOrganisationID]=[LPA_S8].[SupplierOrganisationID]) INNER JOIN [dbo].[tbl_Customer] [LPA_C9] ON [LPA_C9].[CustomerID]=[LPA_S8].[CustomerID]) WHERE ( ( [LPA_S1].[IsDeleted] = 0 AND [LPA_O4].[OrgUnitID] = 1680 AND [LPA_S6].[Status] NOT IN (-1, -2, -5) AND [LPA_S5].[IsPrimaryContact] = 1 AND [LPA_C9].[Status] NOT IN (-1, -2, -5) AND ( [LPA_C9].[isActive] = 1 OR ( [LPA_C9].[isActive] = 0 AND [LPA_C7].[IsRegistrationComplete] = 0)))) ORDER BY [SOPCC].[Name] ASC

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005