Exemple #1
0
        /// <summary>
        /// Factory method that creates a new Sort which controls how the results will be sorted.
        /// </summary>
        /// <param name="expression">Exoression with the property to be used</param>
        /// <param name="ascending">Indicates if sort must by ascending</param>
        public static ISort Sort <T>(Expression <Func <T, object> > expression, bool ascending = true)
        {
            var propertyInfo = ReflectionHelper.GetProperty(expression) as PropertyInfo;

            return(new Sort
            {
                PropertyName = propertyInfo.Name,
                Ascending = ascending,
                Properties = ReflectionHelper.GetNestedProperties <T>(propertyInfo.Name, '.', out var _)
            });
Exemple #2
0
        /// <summary>
        /// Factory method that creates a new IFieldPredicate predicate: [FieldName] [Operator] [Value]
        /// Example: WHERE FirstName = 'Foo'
        /// </summary>
        /// <typeparam name="T">The type of the entity.</typeparam>
        /// <param name="propertyName">Property name that returns the left operand [FieldName].</param>
        /// <param name="op">The comparison operator.</param>
        /// <param name="value">The value for the predicate.</param>
        /// <param name="not">Effectively inverts the comparison operator. Example: WHERE FirstName &lt;&gt; 'Foo'.</param>
        /// <param name="useColumPrefix">Indicates to use or not column prefix on generated SQL</param>
        /// <param name="databaseFunction">Apply database function to field</param>
        /// <param name="databaseFunctionParameters">Parameters to the database function</param>
        /// <returns>An instance of IFieldPredicate.</returns>
        public static IFieldPredicate Field <T>(string propertyName, Operator op, object value, bool not = false, bool useColumPrefix        = true,
                                                DatabaseFunction databaseFunction = DatabaseFunction.None, string databaseFunctionParameters = "") where T : class
        {
            var properties = ReflectionHelper.GetNestedProperties <T>(propertyName, '.', out string propertyInfoName);

            var propertyInfo = typeof(T).GetProperties().SingleOrDefault(x => x.Name.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase));

            return(new FieldPredicate <T>
            {
                PropertyName = propertyInfo != null ? propertyInfo.Name : propertyInfoName,
                Operator = op,
                Value = value,
                Not = not,
                UseTableAlias = useColumPrefix,
                DatabaseFunction = databaseFunction,
                DatabaseFunctionParameters = databaseFunctionParameters,
                Properties = properties
            });
        }