Search Results for

    Show / Hide Table of Contents

    Class QueryableExecuter

    The base class for holding all queries in a generic manner for LemonEdge. The LemonEdge context interface allows access to data across direct DB access and web services, as such we don't use LINQ as it is not fully supported in all circumstances (see OData spec).

    This class is designed to encapsulate the queries possible by LemonEdge across services or direct db access, and is responsible for translating it into appropriate Linq queries where required

    Inheritance
    object
    QueryableExecuter
    QueryableExecuter<T>
    Implements
    ICloneable
    ICloneable<QueryableExecuter>
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: LemonEdge.Utils
    Assembly: LemonEdge.Utils.dll
    Syntax
    [DataContract]
    public abstract class QueryableExecuter : ICloneable, ICloneable<QueryableExecuter>

    Constructors

    QueryableExecuter(bool)

    Creates a new QueryableExecuter specifying whether the underlying query is through OData web service or not

    Declaration
    protected QueryableExecuter(bool oDataQuery)
    Parameters
    Type Name Description
    bool oDataQuery

    Indicates this query is running through an odata webservice rather than direct db connection

    Properties

    AltersQuery

    Indicates if the QueryableExecuter has any order by, where filters, skip or top settings that would alter any IQueryable set when applied to it using ApplyQueryExecuter(IQueryable, QueryableExecuterApplyType, bool)

    Declaration
    public virtual bool AltersQuery { get; }
    Property Value
    Type Description
    bool

    GetSkip

    Indicates the amount of initial records to skip before returning the results, see by Skip(int). This should be associated with an ordering.

    Declaration
    public int? GetSkip { get; }
    Property Value
    Type Description
    int?

    GetTop

    Indicates the maximum amount of records to return, see by Top(int). This should be associated with an ordering.

    Declaration
    public int? GetTop { get; }
    Property Value
    Type Description
    int?

    HasWhereFilter

    Indicates if this QueryableExecuter has any where filters

    Declaration
    public bool HasWhereFilter { get; }
    Property Value
    Type Description
    bool

    IncludeTotalCountInQuery

    Indicates when executing this query is executed it should also execute a count query without skip/top to retrieve the total count too

    Declaration
    public bool IncludeTotalCountInQuery { get; set; }
    Property Value
    Type Description
    bool

    InterfaceType

    Holds the interface type this QueryableExecuter is executing against.

    All queries in LemonEdge can be run against interface or their class definitions

    Declaration
    public abstract Type InterfaceType { get; }
    Property Value
    Type Description
    Type

    IsODataQuery

    Indicates if this underlying query is being executed through a web service or direct db connection

    If this is a direct db connection some queries are changed to make sure the results are consistent across service or direct db connection.

    For instance string comparisons are case insensitive against the database so we change comparisons to use ToLower to make sure in memory queries provide the same results. We can't do this on an OData query as ToLower isn't translatable from Linq to OData, and the odata web service implementation is performing a case insensitive comparison anyway

    Declaration
    public bool IsODataQuery { get; }
    Property Value
    Type Description
    bool

    OrderBys

    A list of all order by filters in this query

    Declaration
    public IEnumerable<QueryableSort> OrderBys { get; }
    Property Value
    Type Description
    IEnumerable<QueryableSort>

    QueryType

    Holds the actual class type this QueryableExecuter is executing against.

    All queries in LemonEdge can be run against interface or their class definitions

    Declaration
    public abstract Type QueryType { get; }
    Property Value
    Type Description
    Type

    TotalCount

    The total count of items returned by executing this queryablefilter. Set by SetTotalCount(int)

    Declaration
    public int? TotalCount { get; }
    Property Value
    Type Description
    int?

    WhereGroupType

    Indicates how all top level Wheres filters are applied together. Either OR or AND them all together.

    Declaration
    public GroupType WhereGroupType { get; set; }
    Property Value
    Type Description
    GroupType

    Wheres

    A list of all where filters in the query

    Declaration
    public IEnumerable<QueryableFilter> Wheres { get; }
    Property Value
    Type Description
    IEnumerable<QueryableFilter>

    Methods

    AddValueTranslator(string, Func<object, object>)

    Allows translation of values when executing in filters.

    Used to translate certain values such as datetime values to specified date time offsets at runtime

    Declaration
    public void AddValueTranslator(string propName, Func<object, object> translator)
    Parameters
    Type Name Description
    string propName

    The property to translate a value for when used in a filter

    Func<object, object> translator

    A function that translates a value into another value for the specified property propName

    AlterPagingByLocalCount(int, int)

    These executers are also used to perform Paging functionality in grids, as such we want to modify skip/count for paging by local modified items

    This method alters the skip by the local count of modified and new items that match these filters, and the top by the local count of deleted items to ensure the results return the correct amount accounting for modified local items

    This can be reset to the actual paging amounts required by using ResetPagingFromLocalCount()

    Declaration
    public void AlterPagingByLocalCount(int count, int deletedCount)
    Parameters
    Type Name Description
    int count

    The local count of modified and new items that match the filters of this QueryableExecuter

    int deletedCount

    The local count of deleted items

    ApplyQueryExecuter(IQueryable, QueryableExecuterApplyType, bool)

    Applies this queryable executer set of filters (definied through the type of Top, Skip, Wheres, OrderBys) to the specified IQueryable items using Linq extensions

    Declaration
    public abstract IQueryable ApplyQueryExecuter(IQueryable items, QueryableExecuterApplyType type, bool isODataQuery)
    Parameters
    Type Name Description
    IQueryable items

    The items to apply the specified filtering of the query to, this can be in memory objects, datasets for direct database access, or web service odata items

    QueryableExecuterApplyType type

    The type of filters to apply

    bool isODataQuery

    Indicates if these items are being executed against web service odata items

    Returns
    Type Description
    IQueryable

    The IQueryable items with the QueryableExecuter filters applied against them

    Clear(QueryableExecuterApplyType)

    Clears all ordering, skip, top and where filters associated with this executer according to the type

    Declaration
    public void Clear(QueryableExecuterApplyType type)
    Parameters
    Type Name Description
    QueryableExecuterApplyType type

    The type of items in the executer to clear. Is a bitwise flag so can be combined

    Clone()

    Creates a new QueryableExecuter that is the same inheriting type as this current one and sets all the values of it to the same as this one

    Declaration
    public QueryableExecuter Clone()
    Returns
    Type Description
    QueryableExecuter

    A new QueryableExecuter that is the same inheriting type as this current one and sets all the values of it to the same as this one

    CopyFromSource(QueryableExecuter)

    Implementation of CopyFromSource(T). Sets all values of this QueryableExecuter to the same as the supplied source

    Declaration
    public virtual void CopyFromSource(QueryableExecuter source)
    Parameters
    Type Name Description
    QueryableExecuter source

    A source QueryableExecuter to copy all values from

    CreateNewItem()

    Returns a new instance of this inheriting type from QueryableExecuter. Used for Clone() implementations to always return the correct new type as an exact copy of the current one

    Declaration
    protected abstract QueryableExecuter CreateNewItem()
    Returns
    Type Description
    QueryableExecuter

    A new QUeryableExecuter that is of the same inheriting type as this current one

    CreateOfType(Type, bool)

    Creates a QueryableExecuter<T> with T being the specified ofType

    Declaration
    public static QueryableExecuter CreateOfType(Type ofType, bool oDataQuery)
    Parameters
    Type Name Description
    Type ofType

    Indicates the generic argument for QueryableExecuter<T>

    bool oDataQuery

    Indicates if this query is being run against an OData web service or not

    Returns
    Type Description
    QueryableExecuter

    A new QueryableExecuter<T>

    CreateOfType(Type, Type, bool)

    Creates a QueryableExecuter<T, TT> with T being the specified ofType and TT being the specified ofTypeTT which implements ofType

    Declaration
    public static QueryableExecuter CreateOfType(Type ofType, Type ofTypeTT, bool oDataQuery)
    Parameters
    Type Name Description
    Type ofType

    An interface that ofTypeTT implements

    Type ofTypeTT

    The actual class being queried

    bool oDataQuery

    Indicates if this query is being run against an OData web service or not

    Returns
    Type Description
    QueryableExecuter

    A new QueryableExecuter<T, TT>

    Deserialize(Type, string, IEnumerable<Type>)

    Deserializes a QueryableExecuter<T> with type t from the specified base64Serialization stream

    Declaration
    public static QueryableExecuter Deserialize(Type t, string base64Serialization, IEnumerable<Type> knownTypes)
    Parameters
    Type Name Description
    Type t

    The type of the QueryableExecuter<T> generic argument

    string base64Serialization

    The serialized stream of the queryableexecuted to restore

    IEnumerable<Type> knownTypes

    Any additional knowntypes for the deserialization

    Returns
    Type Description
    QueryableExecuter

    A new QueryableExecuter<T> from the base64Serialization stream

    Deserialize(Type, Type, string, IEnumerable<Type>)

    Deserializes a QueryableExecuter<T, TT> with type t and tt (which implements t) from the specified base64Serialization stream

    Declaration
    public static QueryableExecuter Deserialize(Type t, Type tt, string base64Serialization, IEnumerable<Type> knownTypes)
    Parameters
    Type Name Description
    Type t

    The T type of the QueryableExecuter<T, TT> generic argument

    Type tt

    The TT type of the QueryableExecuter<T, TT> generic argument

    string base64Serialization

    The serialized stream of the queryableexecuted to restore

    IEnumerable<Type> knownTypes

    Any additional knowntypes for the deserialization

    Returns
    Type Description
    QueryableExecuter

    A new QueryableExecuter<T, TT> from the base64Serialization stream

    Deserialize<T>(string, IEnumerable<Type>)

    Deserializes a QueryableExecuter<T> with type T from the specified base64Serialization stream

    Declaration
    public static QueryableExecuter<T>? Deserialize<T>(string base64Serialization, IEnumerable<Type> knownTypes)
    Parameters
    Type Name Description
    string base64Serialization

    The serialized stream of the queryableexecuted to restore

    IEnumerable<Type> knownTypes

    Any additional knowntypes for the deserialization

    Returns
    Type Description
    QueryableExecuter<T>

    A new QueryableExecuter<T> from the base64Serialization stream

    Type Parameters
    Name Description
    T

    The type of the QueryableExecuter<T> generic argument

    Deserialize<T, TT>(string, IEnumerable<Type>)

    Deserializes a QueryableExecuter<T, TT> with type T and TT (which implements T) from the specified base64Serialization stream

    Declaration
    public static QueryableExecuter<T, TT>? Deserialize<T, TT>(string base64Serialization, IEnumerable<Type> knownTypes) where TT : T
    Parameters
    Type Name Description
    string base64Serialization

    The serialized stream of the queryableexecuted to restore

    IEnumerable<Type> knownTypes

    Any additional knowntypes for the deserialization

    Returns
    Type Description
    QueryableExecuter<T, TT>

    A new QueryableExecuter<T, TT> from the base64Serialization stream

    Type Parameters
    Name Description
    T

    The T type of the QueryableExecuter<T, TT> generic argument

    TT

    The TT type of the QueryableExecuter<T, TT> generic argument

    HasPaging()

    Indicates if this query is setup to use skip or top indicating paging is required

    Declaration
    public bool HasPaging()
    Returns
    Type Description
    bool

    OrderBy(QueryableSort)

    Indicates we want to add the specified QueryableSort to the list of methods for sorting the results. These are executed in the order they are added

    Declaration
    public QueryableExecuter OrderBy(QueryableSort sort)
    Parameters
    Type Name Description
    QueryableSort sort

    A class defining the property and direction we want to sort our results on

    Returns
    Type Description
    QueryableExecuter

    This QueryableExecuter for linking queries

    OrderBy(IEnumerable<QueryableSort>)

    Indicates we want to sort the results by the set of QueryableSort

    Declaration
    public QueryableExecuter OrderBy(IEnumerable<QueryableSort> sorts)
    Parameters
    Type Name Description
    IEnumerable<QueryableSort> sorts

    A collection of ordered methods we want to sort the results by

    Returns
    Type Description
    QueryableExecuter

    This QueryableExecuter for linking queries

    OrderBy(string, Order)

    Creates a new QueryableSort holding the property and direction we want to sort by, and adds it to the collection of sorting methods we want to apply to the results

    Declaration
    public QueryableExecuter OrderBy(string propName, Order direction)
    Parameters
    Type Name Description
    string propName

    The name of a property we want to sort the results by

    Order direction

    The direction in which we want to sort the results by on that data held against that property

    Returns
    Type Description
    QueryableExecuter

    This QueryableExecuter for linking queries

    RemoveOrderBy(string)

    Removes any order by filters in this query that order by the specified orderByName property name

    Declaration
    public void RemoveOrderBy(string orderByName)
    Parameters
    Type Name Description
    string orderByName

    The name of properties that should bre removed from any order by filtering in this query

    ResetPagingFromLocalCount()

    Resets the skip and top values for this QueryableExecuter to their original paging values before AlterPagingByLocalCount(int, int) was called

    Declaration
    public void ResetPagingFromLocalCount()

    SetTotalCount(int)

    Sets the total count of items returned by executing this QueryableExecuter without any skip/top values used

    This is set by the caller using this QueryableExecuter if returning the total amount of items is required by the calling function (usually for paging). Finding this value normally involves calling running the QueryableExecuter query twice, once for the results and the other for just the count without the skip.top values

    Declaration
    public void SetTotalCount(int count)
    Parameters
    Type Name Description
    int count

    indicates the total amount of rows that would be returned by this query without any skip/top values

    SetWhereFilter(GroupType, IEnumerable<QueryableFilter>)

    Clears the current set of where filters against this QueryableExecuter and adds a new set filters with the specified whereGroupBy operator against each filter

    Declaration
    public void SetWhereFilter(GroupType whereGroupBy, IEnumerable<QueryableFilter> filters)
    Parameters
    Type Name Description
    GroupType whereGroupBy

    The operator to use against multiple where filters - either AND or OR

    IEnumerable<QueryableFilter> filters

    The set of new where filters to be applied to this QueryableExecuter, clearing any existing ones

    Skip(int)

    Indicates the amount of records we want to skip before returning the results. This should normally be associated with an order.

    Declaration
    public QueryableExecuter Skip(int count)
    Parameters
    Type Name Description
    int count

    The number of records to skip from the result set

    Returns
    Type Description
    QueryableExecuter

    This QueryableExecuter for linking queries

    Top(int)

    Indicates the maximum number of records to return. This should normally be associated with an order.

    Declaration
    public QueryableExecuter Top(int count)
    Parameters
    Type Name Description
    int count

    The maximum number of results to return

    Returns
    Type Description
    QueryableExecuter

    This QueryableExecuter for linking queries

    TranslateProperty(string, string)

    Translates the specified old property name oldPropertyName used in ordering and where filters to the new property name newPropertyName

    Declaration
    public void TranslateProperty(string oldPropertyName, string newPropertyName)
    Parameters
    Type Name Description
    string oldPropertyName

    The old property name to update all where filters and order by methods to use the new property name instead

    string newPropertyName

    The new property name to update all instances of where filters and order by methods using the old property name

    Where(QueryableFilter)

    Adds the specified filter to the list of Where filters to be applied when executing this query

    Declaration
    public QueryableExecuter Where(QueryableFilter filter)
    Parameters
    Type Name Description
    QueryableFilter filter

    The filter to apply, can be heirarchical containing sub-filters

    Returns
    Type Description
    QueryableExecuter

    This QueryableExecuter for linking queries

    Where(string, SQLOperator, object, bool)

    Creates a QueryableFilter holding a filter for this property, operator and value

    Declaration
    public QueryableExecuter Where(string propName, SQLOperator op, object value, bool isCaseInsensitive = false)
    Parameters
    Type Name Description
    string propName

    The property to compare using the specified op operator against the specified value

    SQLOperator op

    The operation to use as a comparrison against the property propName and the specified value

    object value

    The value to compare against the specified propName property using the specified op operator. Some operators such as IsNull do not need a value

    bool isCaseInsensitive

    Whether the comparison is case-insensitive or not

    Returns
    Type Description
    QueryableExecuter

    This QueryableExecuter for linking queries

    Where(string, string, SQLOperator, bool)

    Creates a QueryableFilter holding a filter for this property, operator and other property

    Declaration
    public QueryableExecuter Where(string propName, string propName2, SQLOperator op, bool oDataQuery = false)
    Parameters
    Type Name Description
    string propName

    The property to compare using the specified op operator against the specified propName2 other property

    string propName2

    The property to compare against the specified propName property using the specified op operator.

    SQLOperator op

    The operation to use as a comparrison against the property propName and the specified propName2 other property

    bool oDataQuery

    Whether the comparison is case-insensitive or not

    Returns
    Type Description
    QueryableExecuter

    This QueryableExecuter for linking queries

    Implements

    ICloneable
    ICloneable<T>

    Extension Methods

    LinqExtensions.AsArray<T>(T)
    LinqExtensions.ToArrayOfOne<T>(T)
    LinqExtensions.ToListOfOne<T>(T)
    MiscExtensions.SetIfNotEqual<T, TP>(T, Expression<Func<T, TP>>, TP)
    QueryExecuterHelper.MergeQueryResults<T>(QueryableExecuter, (List<T> NewItems, List<T> UpdatedItems, List<T> DeletedItems), IQueryable, IEnumerable<T>, IEqualityComparer<T>)
    WeakReferenceExtensions.WeakReference(object)
    SQLExtensions.ToSQLValue(object, bool)
    ReflectionExtensions.ClearEventInvocations(object, string)
    StringExtensions.ToCSVFormatString(object, Type)

    See Also

    QueryableExecuter<T>
    QueryableExecuter<T, TT>
    QueryableFilter
    QueryableSort
    QueryExecuterHelper
    In this article
    Back to top © LemonEdge Technologies. All rights reserved.