예제 #1
0
        /// <summary>
        /// Executes INSERT operation.
        /// </summary>
        /// <typeparam name="T">Type of the entity.</typeparam>
        /// <param name="queryEndpoint">The query endpoint.</param>
        /// <param name="evaluator">The expression, tha specify new values.</param>
        /// <returns>Key of the created entity.</returns>
        public static Key Insert <T>(this QueryEndpoint queryEndpoint, Expression <Func <T> > evaluator) where T : Entity
        {
            var operation = new InsertOperation <T>(queryEndpoint.Provider, evaluator);

            operation.Execute();
            return(operation.Key);
        }
        /// <summary>
        /// Asynchronously executes INSERT operation.
        /// </summary>
        /// <remarks>Multiple active operations in the same session instance are not supported. Use
        /// <see langword="await"/> to ensure that all asynchronous operations have completed before calling
        /// another method in this session.</remarks>
        /// <typeparam name="T">Type of the entity.</typeparam>
        /// <param name="queryEndpoint">The query endpoint.</param>
        /// <param name="evaluator">The expression, tha specify new values.</param>
        /// <param name="token">The cancellation token to terminate execution if necessary.</param>
        /// <returns>Key of the created entity.</returns>
        public static async Task <Key> InsertAsync <T>(this QueryEndpoint queryEndpoint, Expression <Func <T> > evaluator,
                                                       CancellationToken token = default) where T : Entity
        {
            var operation = new InsertOperation <T>(queryEndpoint.Provider, evaluator);
            await operation.ExecuteAsync(token).ConfigureAwait(false);

            return(operation.Key);
        }