예제 #1
0
        /// <summary>
        /// Imports a batch (creates) of <paramref name="items"/> into the <see cref="Container"/>.
        /// </summary>
        /// <typeparam name="TModel">The model <see cref="Type"/>.</typeparam>
        /// <param name="container">The <see cref="Container"/>.</param>
        /// <param name="items">The items to import.</param>
        /// <param name="partitionKey">The optional partition key; where not specified <see cref="PartitionKey.None"/> is used.</param>
        /// <param name="itemRequestOptions">The optional <see cref="ItemRequestOptions"/>.</param>
        /// <param name="setIdentifier">Indicates whether to override the <c>Id</c> where entity implements <see cref="Beef.Entities.IIdentifier"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        /// <remarks>Each item is added individually and is not transactional.</remarks>
        public static async Task ImportBatchAsync <TModel>(this Container container, IEnumerable <TModel> items, Func <TModel, PartitionKey?>?partitionKey = null, ItemRequestOptions?itemRequestOptions = null, bool setIdentifier = false) where TModel : class, new()
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (items == null)
            {
                return;
            }

            foreach (var item in items)
            {
                CosmosDbBase.PrepareEntityForCreate(item, setIdentifier);
                await container.CreateItemAsync(item, partitionKey?.Invoke(item), itemRequestOptions).ConfigureAwait(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Imports a batch (creates) of <see cref="CosmosDbValue{TModel}"/> <paramref name="items"/> into the <see cref="Container"/>.
        /// </summary>
        /// <typeparam name="TModel">The model <see cref="Type"/>.</typeparam>
        /// <param name="container">The <see cref="Container"/>.</param>
        /// <param name="items">The items to import.</param>
        /// <param name="partitionKey">The optional partition key; where not specified <see cref="PartitionKey.None"/> is used.</param>
        /// <param name="itemRequestOptions">The optional <see cref="ItemRequestOptions"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        /// <remarks>Each item is added individually and is not transactional.</remarks>
        public static async Task ImportValueBatchAsync <TModel>(this Container container, IEnumerable <TModel> items, Func <TModel, PartitionKey?>?partitionKey = null, ItemRequestOptions?itemRequestOptions = null) where TModel : class, new()
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (items == null)
            {
                return;
            }

            foreach (var item in items)
            {
                var cdv = new CosmosDbValue <TModel>(item);
                CosmosDbBase.PrepareEntityForCreate(cdv.Value);
                ((ICosmosDbValue)cdv).PrepareBefore();
                await container.CreateItemAsync(cdv, partitionKey?.Invoke(item), itemRequestOptions).ConfigureAwait(false);
            }
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CosmosDbContainer{T, TModel}"/> class.
 /// </summary>
 /// <param name="cosmosDb">The <see cref="CosmosDb"/>.</param>
 /// <param name="dbArgs">The <see cref="CosmosDbArgs{T, TModel}"/>.</param>
 public CosmosDbContainer(CosmosDbBase cosmosDb, CosmosDbArgs <T, TModel> dbArgs)
 {
     CosmosDb  = cosmosDb ?? throw new ArgumentNullException(nameof(cosmosDb));
     DbArgs    = dbArgs ?? throw new ArgumentNullException(nameof(dbArgs));
     Container = cosmosDb.CosmosContainer(DbArgs.ContainerId);
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CosmosDbQuery{T}"/> class.
 /// </summary>
 /// <param name="db">The <see cref="CosmosDbBase"/>.</param>
 /// <param name="queryArgs">The <see cref="CosmosDbArgs"/>.</param>
 /// <param name="query">A function to modify the underlying <see cref="IQueryable{T}"/>.</param>
 internal CosmosDbQuery(CosmosDbBase db, CosmosDbArgs queryArgs, Func <IOrderedQueryable <T>, IQueryable <T> > query = null)
 {
     _db       = Check.NotNull(db, nameof(db));
     QueryArgs = Check.NotNull(queryArgs, nameof(queryArgs));
     _query    = query;
 }