/// <summary>
        /// Retrieves the entities of the specified type.
        /// </summary>
        /// <returns></returns>
        public virtual T[] Index <T>()
            where T : IEntity
        {
            T[] entities = new T[] {};

            using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug))
            {
                LogWriter.Debug("Type name: " + typeof(T).ToString());

                LogWriter.Debug("Enable paging: " + EnablePaging.ToString());
                LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString());

                if (EnablePaging)
                {
                    entities = DataAccess.Data.Indexer.GetPageOfEntities <T>(Location, SortExpression);
                }
                else
                {
                    entities = DataAccess.Data.Indexer.GetEntities <T>();
                }

                if (RequireAuthorisation)
                {
                    AuthoriseIndexStrategy.New <T>().EnsureAuthorised(ref entities);
                }

                LogWriter.Debug("Entity count: " + entities.Length);

                AssignStrategies(entities);

                React(entities);
            }

            return(entities);
        }
        /// <summary>
        /// Index the entity with a references that matches the provided parameters.
        /// </summary>
        /// <param name="propertyName">The name of the property containing the references.</param>
        /// <param name="referencedEntityType">The type of the entity being referenced.</param>
        /// <param name="referencedEntityID">The ID of the entity being referenced.</param>
        /// <returns>The entity matching the provided parameters.</returns>
        public virtual IEntity[] IndexWithReference(string propertyName, string referencedEntityType, Guid referencedEntityID)
        {
            IEntity[] entities = new IEntity[] {};

            using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug))
            {
                LogWriter.Debug("Type name: " + TypeName);

                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Reference entity type: " + referencedEntityType);
                LogWriter.Debug("Referenced entity ID: " + referencedEntityID.ToString());

                LogWriter.Debug("Enable paging: " + EnablePaging.ToString());

                LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString());

                entities = (IEntity[])Reflector.InvokeGenericMethod(this,
                                                                    "IndexWithReference",
                                                                    new Type[] { EntityState.Entities[TypeName].GetEntityType() },
                                                                    new object[] { propertyName, referencedEntityType, referencedEntityID });

                if (RequireAuthorisation)
                {
                    AuthoriseIndexStrategy.New(TypeName).EnsureAuthorised(ref entities);
                }

                React(entities);

                LogWriter.Debug("Entity count: " + entities.Length);
            }
            return(entities);
        }
        /// <summary>
        /// Indexes the entity with a references that matches the provided parameters.
        /// </summary>
        /// <param name="propertyName">The name of the property containing the references.</param>
        /// <param name="referencedEntityType">The type of the entity being referenced.</param>
        /// <param name="referencedEntityID">The ID of the entity being referenced.</param>
        /// <returns>The entity matching the provided parameters.</returns>
        public virtual T[] IndexWithReference <T>(string propertyName, string referencedEntityType, Guid referencedEntityID)
            where T : IEntity
        {
            T[] entities = new T[] {};

            using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug))
            {
                LogWriter.Debug("Type name: " + typeof(T).ToString());

                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Reference entity type: " + referencedEntityType);
                LogWriter.Debug("Referenced entity ID: " + referencedEntityID.ToString());

                LogWriter.Debug("Enable paging: " + EnablePaging.ToString());
                LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString());

                if (EnablePaging)
                {
                    entities = (T[])DataAccess.Data.Indexer.GetPageOfEntitiesWithReference <T>(propertyName, EntityState.GetType(referencedEntityType), referencedEntityID, Location, sortExpression);
                }
                else
                {
                    entities = (T[])DataAccess.Data.Indexer.GetEntitiesWithReference <T>(propertyName, EntityState.GetType(referencedEntityType), referencedEntityID);
                }

                if (RequireAuthorisation)
                {
                    AuthoriseIndexStrategy.New <T>().EnsureAuthorised <T>(ref entities);
                }

                LogWriter.Debug("Entity count: " + entities.Length);

                AssignStrategies(entities);

                React(entities);
            }

            return(entities);
        }