J'essaie de mettre à jour un produit spécifique dans ma base de données.Je passe la valeur du produit du corps et remplacez-la .here ma clé de partition est CATLOG ID.Blow i Donner l'exemple de mon code s'il vous plaît dites-moi ce que j'ai tort? Corps JSON: P>
P>
<pre class="rawExceptionStackTrace">Microsoft.Azure.Documents.BadRequestException: ResourceType Document is unexpected.
ActivityId: 62f61852-d2a7-466a-9765-80db1d02de32, Windows/10.0.17134 documentdb-netcore-sdk/2.4.0
 at Microsoft.Azure.Documents.PathsHelper.GeneratePathForNameBased(ResourceType resourceType, String resourceFullName, Boolean isFeed, Boolean notRequireValidation)
 at Microsoft.Azure.Documents.GatewayStoreModel.GetEntityUri(DocumentServiceRequest entity)
 at Microsoft.Azure.Documents.GatewayStoreModel.ProcessMessageAsync(DocumentServiceRequest request, CancellationToken cancellationToken)
 at Microsoft.Azure.Documents.Client.DocumentClient.ProcessRequestAsync(DocumentServiceRequest request, IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken cancellationToken)
 at Microsoft.Azure.Documents.Client.DocumentClient.ReplaceDocumentPrivateAsync(String documentLink, Document document, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken cancellationToken)
 at Microsoft.Azure.Documents.BackoffRetryUtility`1.ExecuteRetryAsync(Func`1 callbackMethod, Func`3 callShouldRetry, Func`1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action`1 preRetryCallback)
 at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException)
 at Microsoft.Azure.Documents.BackoffRetryUtility`1.ExecuteRetryAsync(Func`1 callbackMethod, Func`3 callShouldRetry, Func`1 inBackoffAlternateCallbackMethod, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action`1 preRetryCallback)
 at Microsoft.Azure.Documents.Client.DocumentClient.ReplaceDocumentInlineAsync(String documentLink, Object document, RequestOptions options, CancellationToken cancellationToken)
 at CatalogAPI.Services.CatalogRepository.UpdateProductByIdAsync(Guid id, Product order) in D:\UCDP\UCDP\UCDP\src\Service\Catalog\CatalogAPI\Services\CatalogRepository.cs:line 322
 at CatalogAPI.Controllers.CatalogController.UpdateProductByIdAsync(Guid id, Product order) in D:\UCDP\UCDP\UCDP\src\Service\Catalog\CatalogAPI\Controllers\CatalogController.cs:line 158
 at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
 at System.Threading.Tasks.ValueTask`1.get_Result()
 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
 at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
 at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
 at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
 at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
 at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
 at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
 at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
 at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
 at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
 at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)</pre>
3 Réponses :
Lorsque vous appelez . L'affectation devrait regarder comme ceci: p> REPTERDOCUMENTASYNC CODE> STROND> Vous devez fournir l'URI COLLECTION CODE> FORT>.
ELTEREDOCTIONSYNC Les appels ont besoin de l'URI du document, pas du documentCollection.
var catalogDocument = await _cosmosClient.ReplaceDocumentAsync(
UriFactory.CreateDocumentUri(
_azureCosmosDbOptions.Value.DatabaseId, "catalog", order.Id), order, requestOptions);
Ceci est facile à négliger que upserdocumentasync code> nécessite l'URI de la collection.
J'ai finalement fait comme soufflage:
p>
public async Task<Catalog> UpdateProductIdAsync(
Guid productid,
Product productData)
{
var feedOptions =
new FeedOptions
{
MaxItemCount = -1,
EnableCrossPartitionQuery = true
};
var query =
$"SELECT catalog.id,catalog.VendorName,catalog.Industy FROM catalog join industry in catalog.Industy join category in industry.Category join product in category.Subcategory.Product where product.Id ='" + productid + "'";
var catlog = _cosmosClient.CreateDocumentQuery<Catalog>(UriFactory.CreateDocumentCollectionUri(
_azureCosmosDbOptions.Value.DatabaseId, "catalog"), query, feedOptions).AsEnumerable().FirstOrDefault();
if (catlog != null)
{
foreach (var item in catlog.Industy)
{
foreach (var cat in item.Category)
{
Product product = cat.Subcategory.Product.FirstOrDefault(p => p.Id == productid);
if (product != null)
{
product.Name = productData.Name == null ? product.Name : productData.Name;
product.Addons = productData.Addons == null ? product.Addons : productData.Addons;
product.CurrentQuantity = productData.CurrentQuantity == null ? product.CurrentQuantity : productData.CurrentQuantity;
product.MethodOfPreparation = productData.MethodOfPreparation == null ? product.MethodOfPreparation : productData.MethodOfPreparation;
product.Price = productData.Price == null ? product.Price : productData.Price;
product.Tag = productData.Tag == null ? product.Tag : productData.Tag;
product.Unit = productData.Unit == null ? product.Unit : productData.Unit;
product.hasMethodOfPreparation = productData.hasMethodOfPreparation == false ? product.hasMethodOfPreparation : productData.hasMethodOfPreparation;
break;
}
}
break;
}
}
var requestOptions =
new RequestOptions
{
PartitionKey = new Microsoft.Azure.Documents.PartitionKey(catlog.Id.ToString())
};
var orderDocument = await _cosmosClient.ReplaceDocumentAsync(
UriFactory.CreateDocumentUri(
_azureCosmosDbOptions.Value.DatabaseId, "catalog", catlog.Id.ToString()), catlog, requestOptions);
return
(Catalog)((dynamic)catlog);
}