Get EntityFields from TypedList

Posts   
 
    
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 22-Jan-2012 12:48:56   

Hello,

I have 1 question about getting entityfields from TypedList.

Currently this field is private :-(

I have this method:

public static void CreateSortorder(ITypedListLgp2 typedList, SortExpression vSort, string sortstring)
        {
            if (!string.IsNullOrEmpty(sortstring))
            {
                List<string> sortlijst = new List<string>();

                const string and = "~and~";

                while (sortstring.Contains(and))
                {
                    int pos = sortstring.IndexOf(and);

                    // we maken 1 lijn aan met filterdata
                    sortlijst.Add(sortstring.Substring(0, pos));

                    // de overschot van stringfilter aan de filter terug geven.
                    sortstring = sortstring.Substring(pos + and.Length, sortstring.Length - (pos + and.Length));
                }

                sortlijst.Add(sortstring);

                foreach (string srt in sortlijst)
                {

                    string[] param = srt.Split('-');

                    List<EntityFields2> ef = ((SD.LLBLGen.Pro.ORMSupportClasses.EntityFields2) (typedList.GetFieldsInfo()))._entityFields;

                    // get the involved field
                    IEntityField2 Sortfield = null; //((EntityFields2)EntityFieldsFactory.CreateEntityFieldsObject(entityType))[param[0]];

                    // build the sorter
                    switch (param[1])
                    {
                        case "asc":
                            vSort.Add(new SortClause(Sortfield, null, SortOperator.Ascending));
                            break;
                        case "desc":
                            vSort.Add(new SortClause(Sortfield, null, SortOperator.Descending));
                            break;
                        default:
                            throw new Exception("LLBLGEN custom Filter type not supported");
                    }
                }
            }
        }

I use this method for my MVC telerik grid.

The grid does an action and that returns a json result. (The data for inside the grid)

Now the Telerik grid has his own techniek to send his filter, order by.

Now what i do is create the sortorder.

Can you help me out ?

Or is there a better way to work with LLBLgen objects --> to Json (And had sort, filter, group by support ?)

Thanks

Kris

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Jan-2012 03:37:35   

It's not necessary to you create the field. Just look into the ones obtained by GetFieldInfo. Approx code:

foreach (string srt in sortlijst)
                {

                    string[] param = srt.Split('-');

                    IEntityFields2 ef = typedList.GetFieldsInfo();

                    // get the involved field
                    IEntityField2 Sortfield = ef[param[0]];

                    // build the sorter
                    switch (param[1])
                    {
                        case "asc":
                            vSort.Add(new SortClause(Sortfield, null, SortOperator.Ascending));
                            break;
                        case "desc":
                            vSort.Add(new SortClause(Sortfield, null, SortOperator.Descending));
                            break;
                        default:
                            throw new Exception("LLBLGEN custom Filter type not supported");
                    }
                }
David Elizondo | LLBLGen Support Team
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 24-Jan-2012 09:58:17   

Thanks ;-)