如何删除产品

时间:2019-06-09 00:36:34

标签: sql asp.net-core azure-cosmosdb

如何使用asp.net核心网络api删除以下查询。

查询:

Select * 
From catalog.Industy.Category.Subcategory.Product 
Where Product.Id="97c27069-4a16-44c3-bdf1-627c8ea339fa"

json正文:

{
    "id": "9fc41e97-c32e-45e6-853f-ae7993cbc773",
    "Industy": {
        "Id": "40f5a6f5-2947-469c-8d29-6aa84de982cb",
        "Category": {
            "Subcategory": {     
                "Product": {
                    "Addons": {   
                    },
                    "MethodOfPreparation": {

                    }
                }
            }
        }
    }

2 个答案:

答案 0 :(得分:0)

对于cosmosdb sql api,应该是

 SELECT *
    FROM Products p
    WHERE p.Industy.Category.Subcategory.Product.Id = "97c27069-4a16-44c3-bdf1-627c8ea339fa"

其中“产品”是容器的名称

答案 1 :(得分:0)

也许您应该首先阅读使用CosmosDB的文档: here

在此页面上,您可以查看如何查询产品,然后从收藏夹中删除此记录:

 var query = client.CreateDocumentQuery<YourDocumentModel>(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName),
 "<your sql>",
 queryOptions);

使用此结果,您可以更新对象(yourDocumentModelObject)并将产品从子类别中删除。 然后通过以下操作将其保存回集合中:

await client.UpsertDocumentAsync<YourDocumentModel>(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName),
yourDocumentModelObject);