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
Inherited Members
Namespace: LemonEdge.Utils
Assembly: Utils.dll
Syntax
[DataContract]
public abstract class QueryableExecuter : ICloneable, ICloneable<QueryableExecuter>
Constructors
QueryableExecuter(Boolean)
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 |
---|---|---|
System.Boolean | oDataQuery | Indicates this query is running through an odata webservice rather than direct db connection |
Properties
AltersQuery
Indicates if thei 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, Boolean)
Declaration
public virtual bool AltersQuery { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
GetSkip
Indicates the amount of initial records to skip before returning the results, see by Skip(Int32). This should be associated with an ordering.
Declaration
public int? GetSkip { get; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Int32> |
GetTop
Indicates the maximum amount of records to return, see by Top(Int32). This should be associated with an ordering.
Declaration
public int? GetTop { get; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Int32> |
HasWhereFilter
Indicates if this QueryableExecuter has any where filters
Declaration
public bool HasWhereFilter { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
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 |
---|---|
System.Boolean |
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 |
---|---|
System.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 |
---|---|
System.Boolean |
OrderBys
A list of all order by filters in this query
Declaration
public IEnumerable<QueryableSort> OrderBys { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.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 |
---|---|
System.Type |
TotalCount
The total count of items returned by executing this queryablefilter. Set by SetTotalCount(Int32)
Declaration
public int? TotalCount { get; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Int32> |
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 |
---|---|
System.Collections.Generic.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 |
---|---|---|
System.String | propName | The property to translate a value for when used in a filter |
System.Func<System.Object, System.Object> | translator | A function that translates a value into another value for the specified property |
AlterPagingByLocalCount(Int32, Int32)
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 |
---|---|---|
System.Int32 | count | The local count of modified and new items that match the filters of this QueryableExecuter |
System.Int32 | deletedCount | The local count of deleted items |
ApplyQueryExecuter(IQueryable, QueryableExecuterApplyType, Boolean)
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 |
---|---|---|
System.Linq.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 |
System.Boolean | isODataQuery | Indicates if these items are being executed against web service odata items |
Returns
Type | Description |
---|---|
System.Linq.IQueryable | The IQueryable |
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, Boolean)
Creates a QueryableExecuter<T> with T being the specified ofType
Declaration
public static QueryableExecuter CreateOfType(Type ofType, bool oDataQuery)
Parameters
Type | Name | Description |
---|---|---|
System.Type | ofType | Indicates the generic argument for QueryableExecuter<T> |
System.Boolean | 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, Boolean)
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 |
---|---|---|
System.Type | ofType | An interface that |
System.Type | ofTypeTT | The actual class being queried |
System.Boolean | 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 |
---|---|---|
System.Type | t | The type of the QueryableExecuter<T> generic argument |
System.String | base64Serialization | The serialized stream of the queryableexecuted to restore |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Any additional knowntypes for the deserialization |
Returns
Type | Description |
---|---|
QueryableExecuter | A new QueryableExecuter<T> from the |
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 |
---|---|---|
System.Type | t | The T type of the QueryableExecuter<T, TT> generic argument |
System.Type | tt | The TT type of the QueryableExecuter<T, TT> generic argument |
System.String | base64Serialization | The serialized stream of the queryableexecuted to restore |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Any additional knowntypes for the deserialization |
Returns
Type | Description |
---|---|
QueryableExecuter | A new QueryableExecuter<T, TT> from the |
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 |
---|---|---|
System.String | base64Serialization | The serialized stream of the queryableexecuted to restore |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Any additional knowntypes for the deserialization |
Returns
Type | Description |
---|---|
QueryableExecuter<T> | A new QueryableExecuter<T> from the |
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 |
---|---|---|
System.String | base64Serialization | The serialized stream of the queryableexecuted to restore |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Any additional knowntypes for the deserialization |
Returns
Type | Description |
---|---|
QueryableExecuter<T, TT> | A new QueryableExecuter<T, TT> from the |
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 |
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 |
---|---|---|
System.Collections.Generic.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 |
---|---|---|
System.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 |
---|---|---|
System.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(Int32, Int32) was called
Declaration
public void ResetPagingFromLocalCount()
SetTotalCount(Int32)
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 |
---|---|---|
System.Int32 | 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 |
System.Collections.Generic.IEnumerable<QueryableFilter> | filters | The set of new where filters to be applied to this QueryableExecuter, clearing any existing ones |
Skip(Int32)
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 |
---|---|---|
System.Int32 | count | The number of records to skip from the result set |
Returns
Type | Description |
---|---|
QueryableExecuter | This QueryableExecuter for linking queries |
Top(Int32)
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 |
---|---|---|
System.Int32 | 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 |
---|---|---|
System.String | oldPropertyName | The old property name to update all where filters and order by methods to use the new property name instead |
System.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)
Creates a QueryableFilter holding a filter for this property, operator and value
Declaration
public QueryableExecuter Where(string propName, SQLOperator op, object value)
Parameters
Type | Name | Description |
---|---|---|
System.String | propName | The property to compare using the specified |
SQLOperator | op | The operation to use as a comparrison against the property |
System.Object | value | The value to compare against the specified |
Returns
Type | Description |
---|---|
QueryableExecuter | This QueryableExecuter for linking queries |
Where(String, String, SQLOperator)
Creates a QueryableFilter holding a filter for this property, operator and other property
Declaration
public QueryableExecuter Where(string propName, string propName2, SQLOperator op)
Parameters
Type | Name | Description |
---|---|---|
System.String | propName | The property to compare using the specified |
System.String | propName2 | The property to compare against the specified |
SQLOperator | op | The operation to use as a comparrison against the property |
Returns
Type | Description |
---|---|
QueryableExecuter | This QueryableExecuter for linking queries |
Explicit Interface Implementations
ICloneable.Clone()
Implementation of 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
object ICloneable.Clone()
Returns
Type | Description |
---|---|
System.Object | 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 |
ICloneable.CopyFromSource(Object)
Implementation of CopyFromSource(Object). Sets all values of this QueryableExecuter to the same as the supplied source
Declaration
void ICloneable.CopyFromSource(object source)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | A source QueryableExecuter to copy all values from |