Beispiel #1
0
        /// <summary>
        /// Gets the first entry that meets the criteria from the expression
        /// </summary>
        /// <param name="expression">The expression like: "LastName = 'Jones'",  "Price = 50.00"</param>
        /// <param name="sortColumn">The sort column.</param>
        /// <param name="sortType">Type of the sort.</param>
        /// <returns></returns>
        public T GetFirstWhere(string expression, string sortColumn = "", objectTableSortEnum sortType = objectTableSortEnum.none)
        {
            T   output = default(T);
            var items  = base.GetWhere(expression, 1, sortColumn, sortType);

            foreach (object item in items)
            {
                output = (T)item;
                break;
            }
            return(output);
        }
Beispiel #2
0
        /// <summary>
        /// Returns the list of instances for the specified expression <see cref="DataTable.Select(string)"/>
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="limit">The limit.</param>
        /// <returns></returns>
        protected List <object> GetWhere(string expression, int limit = -1, string sortColumn = "", objectTableSortEnum sortType = objectTableSortEnum.none)
        {
            List <object> output = new List <object>();

            if (IsInstanceLinkActive)
            {
                foreach (object item in instanceRegistry)
                {
                    UpdateBase(item);
                }
            }

            DataRow[] rows = null;

            if (sortType != objectTableSortEnum.none)
            {
                sortColumn = imbSciStringExtensions.removeEndsWith(sortColumn, " ASC");
                sortColumn = imbSciStringExtensions.removeEndsWith(sortColumn, " asc");
                sortColumn = imbSciStringExtensions.removeEndsWith(sortColumn, " DESC");
                sortColumn = imbSciStringExtensions.removeEndsWith(sortColumn, " desc");
                sortColumn = imbSciStringExtensions.add(sortColumn, sortType.ToString(), " ");
            }

            rows = tableSelect(expression, sortColumn);

            if (rows != null)
            {
                if (rows.Any())
                {
                    if (limit > 0)
                    {
                        limit = Math.Min(rows.Count(), limit);
                        rows  = rows.Take(limit).ToArray();
                    }

                    output = GetObjectFromRows(rows);
                }
            }

            return(output);
        }
Beispiel #3
0
        public List <T> GetWhere(string expression, int limit = -1, string sortColumn = "", objectTableSortEnum sortType = objectTableSortEnum.none)
        {
            List <T> output = new List <T>();
            var      items  = base.GetWhere(expression, limit, sortColumn, sortType);

            foreach (object item in items)
            {
                output.Add((T)item);
            }
            return(output);
        }