TypedList and GetFieldsInfo-Method

Posts   
 
    
johnny
User
Posts: 3
Joined: 13-Feb-2007
# Posted on: 13-Feb-2007 03:32:01   

Hi there, I am missing the GetFieldsInfo-method in my generated TypedList. Do I have to implement it myself? I use the selfservicing-scenario and would like to sort by a field of which i have given its name. Unfortunately using the entitie's fields will not be sufficient as i need the related fields of the list, too. Thanks in advance Johnny

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Feb-2007 07:50:26   

GetFieldsInfo() is used in the Adapter model. Would you please post a code snippet of what you are trying to do?

And the following is an example from the manual showing how to use a typed list with sort:

// [C#]
OrderCustomerTypedList orderCustomer = new OrderCustomerTypedList();
IPredicateExpression filter = new PredicateExpression(CustomerFields.Country == "Brazil");
ISortExpression sorter = new SortExpression(OrderFields.Freight | SortOperator.Ascending);
// Set allowDuplicates to true, because we sort on a field that is not in our resultset and we use SqlServer.
orderCustomer.Fill(0, sorter, true, filter);
' [VB.NET]
Dim orderCustomer As New OrderCustomerTypedList()
Dim filter As IPredicateExpression = New PredicateExpression( _
    New FieldCompareValuePredicate(CustomerFields.Country, ComparisonOperator.Equal, "Brazil"))
Dim sorter As ISortExpression = New SortExpression( _
    New SortClause(OrderFields.Freight, SortOperator.Ascending))
' Set allowDuplicates to true, because we sort on a field that is not in our resultset and we use SqlServer.
orderCustomer.Fill(0, sorter, True, filter)

johnny
User
Posts: 3
Joined: 13-Feb-2007
# Posted on: 13-Feb-2007 18:46:52   

Hi, I am trying to sort a TypedList by a fieldName (a string!) to order by columns in a table. This is basically what I wanted to do, but since I am using selfservicing, I don't know how to realize it.


        public ICollection GetOrderedList(string orderFieldName, bool desc)
        {
            MyTypedList view = new MyTypedList();
            if (orderFieldName != string.Empty && orderFieldName != null)
            {
                SortOperator op = desc ? SortOperator.Descending : SortOperator.Ascending;
                EntityField orderField = view.GetFieldsInfo()[orderFieldName];
                // this won't work because there are related fields (not only of one entity)
                //EntityField orderField = (EntityField)(new MyEntity()).Fields[orderFieldName];
                ISortExpression sorter = new SortExpression(orderField | op);
                view.Fill(0, sorter, true, null);
            }
            else
            {
                view.Fill();
            }
            return view.Rows;
        }

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 14-Feb-2007 02:17:05   

Would you be able to retrieve the fields that you need from the typed list using the lists BuildResultSet method?

johnny
User
Posts: 3
Joined: 13-Feb-2007
# Posted on: 14-Feb-2007 07:37:45   

Thank you very much, this indeed made the trick.

Edit: The method now looks like this, for those who may need it too:


        public ICollection GetOrderedList(string orderFieldName, bool desc)
        {
            MyTypedList view = new MyTypedList();
            if (orderFieldName != string.Empty && orderFieldName != null)
            {
                SortOperator op = desc ? SortOperator.Descending : SortOperator.Ascending;
                IEntityFields fields = view.BuildResultSet();
                EntityField orderField = (EntityField)fields[orderFieldName];
                ISortExpression sorter = new SortExpression(orderField | op);
                view.Fill(0, sorter, true, null);
            }
            else
            {
                view.Fill();
            }
            return view.Rows;
        }