private void PerformAutoLogic(esDataSourceSelectEventArgs e)
        {
            esDynamicQuery query = e.Query != null ? e.Query : e.Collection.es.Query;

            IDynamicQuerySerializableInternal iQuery = query as IDynamicQuerySerializableInternal;

            if (this.autoPaging)
            {
                query.es.PageNumber = e.PageNumber;
                query.es.PageSize   = e.PageSize;
            }

            if (this.autoSorting)
            {
                if (e.SortItems != null)
                {
                    foreach (esDataSourceSortItem sortItem in e.SortItems)
                    {
                        esColumnMetadata col = e.Collection.es.Meta.Columns.FindByPropertyName(sortItem.Property);
                        if (col != null)
                        {
                            query.OrderBy(col.Name, sortItem.Direction);
                        }
                        else if (sortItem.Property[0] == '<')
                        {
                            query.OrderBy(sortItem.Property, sortItem.Direction);
                        }
                    }
                }
                else
                {
                    if (this.AutoPaging)
                    {
                        List <esColumnMetadata> pks = e.Collection.es.Meta.Columns.PrimaryKeys;
                        if (pks != null)
                        {
                            foreach (esColumnMetadata pk in pks)
                            {
                                query.OrderBy(pk.Name, esOrderByDirection.Ascending);
                            }
                        }
                    }
                }
            }

            if (this.autoSorting || this.AutoPaging)
            {
                if (e.Query != null)
                {
                    IEntityCollection iColl = e.Collection as IEntityCollection;
                    iColl.HookupQuery(query);
                }

                query.Load();
            }
        }