public void GetSortExpressionStringTest()
        {
            SortExpression target   = new SortExpression();
            string         expected = string.Empty;
            string         actual;

            actual = target.GetSortExpressionString();
            Assert.AreEqual(expected, actual);
        }
        public void GetSortExpressionStringTest2()
        {
            SortExpression target = new SortExpression();

            target.AddSort(new SortInfo(vTestCaseTester.ColumnNames.FieldString, SortDirectionEnum.DESC));
            string expected = vTestCaseTester.ColumnNames.FieldString + " " + "DESC";
            string actual;

            actual = target.GetSortExpressionString();
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Gets the by filter.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public System.Collections.IList GetByFilter(GetByFilterParameters parameters)
        {
            //NHibernateSession.Clear(); // temprorary fix for Dataaccess bug

            // used from http://ayende.com/blog/4023/nhibernate-queries-examples

            string           selectColumns = "";
            SortExpression   sort          = parameters.Sort;
            FilterExpression filter        = parameters.Filter;
            int pageIndex = parameters.PageIndex;
            int pageSize  = parameters.PageSize;

            if (pageSize == -1) // invalid value
            {
                pageSize = this.Entity.DefaultPageSize;
            }

            // Column Names
            ICollection <string> colNames = parameters.SelectColumns;

            if (colNames != null && colNames.Count > 0)
            {
                // adding ID field name to any select from the database to prevent null (-1) id problems
                if (string.IsNullOrEmpty(this.Entity.IDFieldName) == false)
                {
                    if (colNames.Contains(this.Entity.IDFieldName) == false)
                    {
                        colNames.Add(this.Entity.IDFieldName);
                    }
                }
                selectColumns = "Select ";
                int i = 0;
                foreach (string col in colNames)
                {
                    selectColumns += col;
                    if (i != colNames.Count - 1)
                    {
                        selectColumns += ",";
                    }
                    else
                    {
                        selectColumns += " ";
                    }
                    i++;
                }
            }

            // sort
            string sortString = sort.GetSortExpressionString();

            if (string.IsNullOrEmpty(sortString) == false)
            {
                sortString = " Order By " + sortString;
            }

            // adding filter
            List <object> parameterValues = new List <object>();
            string        filterString    = filter.GetFilterString(parameterValues);

            if (string.IsNullOrEmpty(filterString) == false)
            {
                filterString = " Where (" + filterString + ")";
            }

            string hqlQuery = selectColumns + "from " + this.GetTableName(parameters.SourceType) + filterString + sortString;

            hqlQuery = hqlQuery.Replace("[", "").Replace("]", "");
            var query = NHibernateSession.CreateQuery(hqlQuery);

            // adding parameters
            for (int i = 0; i < parameterValues.Count; i++)
            {
                string paramName = Filter.ParameterPrefix.Substring(1) + i;
                if (parameterValues[i] is System.Collections.ICollection)  // for in operator, we can have a list of items. It works in HQL, but we need to pass it as parameterList
                // read more here: http://stackoverflow.com/questions/3390561/nhibernate-update-single-field-without-loading-entity
                {
                    query.SetParameterList(paramName, (System.Collections.ICollection)parameterValues[i]);
                }
                else
                {
                    query.SetParameter(paramName, parameterValues[i]);
                }
            }

            // set paging
            query.SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize);

            if (colNames == null)
            {
                if (parameters.SourceType == GetSourceTypeEnum.Table)
                {
                    return(query.List <T>() as List <T>);
                }
                else
                {
                    return(query.List <V>() as List <V>);
                }
            }
            else
            {
                var list = query.List();
                return(ConvertToTypedList(parameters.SourceType, colNames, list));
            }
        }