Example #1
0
        /// <summary>
        /// Executes a query to get a single entity of the specified type using a string identifier. Use this
        /// as a short cut instead of creating a dedicated IQuery class.
        /// </summary>
        /// <typeparam name="TEntity">type of entity to return</typeparam>
        /// <param name="id">Id of the entity to get. Null or empty values will always return default(TEntity).</param>
        /// <param name="ex">
        /// If specified this will execute the query under
        /// the specified context. Useful for running the query under a higher privalidge account.
        /// </param>
        /// <returns>TEntity instance if found; otherwise default(TEntity)</returns>
        public static async Task <TEntity> GetByIdAsync <TEntity>(this IQueryExecutor executor, string id, IExecutionContext ex)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(default(TEntity));
            }
            var query = new GetByStringQuery <TEntity>()
            {
                Id = id
            };

            return(await executor.ExecuteAsync(query, ex));
        }
Example #2
0
        /// <summary>
        /// Executes a query to get a single entity of the specified type using a string identifier. Use this
        /// as a short cut instead of creating a dedicated IQuery class.
        /// </summary>
        /// <typeparam name="TEntity">type of entity to return</typeparam>
        /// <param name="id">Id of the entity to get. Null or empty values will always return default(TEntity).</param>
        /// <returns>TEntity instance if found; otherwise default(TEntity)</returns>
        public static TEntity GetById <TEntity>(this IQueryExecutor executor, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(default(TEntity));
            }
            var query = new GetByStringQuery <TEntity>()
            {
                Id = id
            };

            return(executor.Execute(query));
        }