{"id":13499,"date":"2022-06-28T14:33:16","date_gmt":"2022-06-28T21:33:16","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=13499"},"modified":"2025-06-13T21:51:46","modified_gmt":"2025-06-14T04:51:46","slug":"asp-net-core-crud-nosql-part-4","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-nosql-part-4\/","title":{"rendered":"CRUD do ASP.NET Core com NoSQL: Parte 4"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Os aplicativos ASP.NET CRUD incluem a intera\u00e7\u00e3o com dados que consistem em criar, ler, atualizar e excluir. Em <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-with-nosql-part-1\/\"><span style=\"font-weight: 400;\">Parte 1<\/span><\/a><span style=\"font-weight: 400;\">Em seguida, configuramos um projeto b\u00e1sico do ASP.NET Core. Em <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-crud-nosql-part-2\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Parte 2<\/span><\/a><span style=\"font-weight: 400;\">adicionamos o primeiro <\/span><i><span style=\"font-weight: 400;\">ler<\/span><\/i><span style=\"font-weight: 400;\"> usando uma consulta SQL++ em rela\u00e7\u00e3o aos dados da lista de desejos. Em <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-nosql-part-3\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Parte 3<\/span><\/a><span style=\"font-weight: 400;\">Adicionamos outro ponto de extremidade de leitura, desta vez usando a API de valor-chave.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">At\u00e9 este ponto, as \u00fanicas modifica\u00e7\u00f5es de dados que fizemos foram diretamente na interface do usu\u00e1rio do Couchbase Capella. Nesta postagem, vamos adicionar um endpoint para lidar com a cria\u00e7\u00e3o e a atualiza\u00e7\u00e3o dos dados da lista de desejos.<\/span><\/p>\n<h2><b>SQL++ versus valor-chave: Revisitado<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">O SQL++ inclui <\/span><em><span style=\"font-weight: 400;\">INSERIR<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">ATUALIZA\u00c7\u00c3O<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">DELETE<\/span><\/em><span style=\"font-weight: 400;\"> sintaxe. Portanto, poder\u00edamos usar o SQL++ para criar um ponto de extremidade para alterar dados. Ele seria muito semelhante ao c\u00f3digo escrito em <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-crud-nosql-part-2\/\"><span style=\"font-weight: 400;\">Parte 2<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Uma palavra-chave no SQL++ que voc\u00ea talvez n\u00e3o tenha visto antes \u00e9 <\/span><em><span style=\"font-weight: 400;\">UPSERT<\/span><\/em><span style=\"font-weight: 400;\">. Como voc\u00ea pode imaginar, \u00e9 uma combina\u00e7\u00e3o de <\/span><em><span style=\"font-weight: 400;\">ATUALIZA\u00c7\u00c3O<\/span><\/em><span style=\"font-weight: 400;\"> e <\/span><em><span style=\"font-weight: 400;\">INSERIR<\/span><\/em><span style=\"font-weight: 400;\"><em>.<\/em> Uma atualiza\u00e7\u00e3o ocorrer\u00e1 se os dados j\u00e1 existirem; uma inser\u00e7\u00e3o ocorrer\u00e1 se n\u00e3o existirem. Veja como pode ser um endpoint upsert usando SQL++:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">[HttpPost]\r\n[Route(\"api\/editWithSql\")]\r\npublic async Task&lt;IActionResult&gt; CreateOrEditWithSql(WishlistItem item)\r\n{\r\n\u00a0 \u00a0 var bucket = await _bucketProvider.GetBucketAsync(\"demo\");\r\n\u00a0 \u00a0 var cluster = bucket.Cluster;\r\n\r\n\u00a0 \u00a0 var id = item.Id ?? Guid.NewGuid();\r\n\r\n\u00a0 \u00a0 var result = await cluster.QueryAsync&lt;WishlistItem&gt;(\r\n\u00a0 \u00a0 \u00a0 \u00a0 @\"UPSERT INTO demo._default.wishlist (KEY, VALUE)\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 VALUES ($id, { \"\"name\"\" : $name });\",\r\n\u00a0 \u00a0 \u00a0 \u00a0 options =&gt; options\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .Parameter(\"id\", id)\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .Parameter(\"name\", item.Name)\r\n\u00a0 \u00a0 );\r\n\r\n\u00a0 \u00a0 return Ok(result);\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">H\u00e1 dois aspectos importantes a serem destacados sobre esse c\u00f3digo:<\/span><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ele lida tanto com a cria\u00e7\u00e3o quanto com a atualiza\u00e7\u00e3o. Se <\/span><em><span style=\"font-weight: 400;\">item<\/span><\/em><span style=\"font-weight: 400;\"> tiver um ID nulo, esse c\u00f3digo pressup\u00f5e que um novo item da lista de desejos est\u00e1 sendo criado.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Parametriza\u00e7\u00e3o: assim como nos bancos de dados relacionais, o SQL++ pode ser vulner\u00e1vel a <\/span><a href=\"https:\/\/owasp.org\/www-community\/attacks\/SQL_Injection\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Inje\u00e7\u00e3o de SQL<\/span><\/a><span style=\"font-weight: 400;\">portanto, a parametriza\u00e7\u00e3o \u00e9 altamente recomendada. Observe que a sintaxe do SQL++ usa <\/span><em><span style=\"font-weight: 400;\">$<\/span><\/em><span style=\"font-weight: 400;\"> para indicar par\u00e2metros nomeados (por exemplo <\/span><em><span style=\"font-weight: 400;\">$id<\/span><\/em><span style=\"font-weight: 400;\"> e <\/span><em><span style=\"font-weight: 400;\">$name<\/span><\/em><span style=\"font-weight: 400;\">).<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Esse endpoint funcionar\u00e1. Mas, como foi o caso em <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-nosql-part-3\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Parte 3<\/span><\/a><span style=\"font-weight: 400;\">Se o Couchbase for um banco de dados, n\u00e3o precisaremos usar o SQL++ para interagir com o Couchbase. De fato, crit\u00e9rios muito semelhantes se aplicam \u00e0 decis\u00e3o de quando usar valor-chave e quando usar SQL++:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Caso de uso<\/strong><\/td>\n<td><strong>Chave-valor?<\/strong><\/td>\n<td><strong>Por que ou por que n\u00e3o?<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Criar um novo usu\u00e1rio com a chave \"73892\"<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Sim<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Acesso direto<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Modificar um usu\u00e1rio com a chave \"73892\"<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Sim<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Acesso direto<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Modificar apenas o endere\u00e7o de e-mail de um usu\u00e1rio com a chave \"73892\"<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Sim<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Mesmo que o documento do usu\u00e1rio seja grande, o Couchbase tem um recurso baseado em chave <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/guides\/updating-data.html#updating-a-sub-document\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">API de subdocumento<\/span><\/a><span style=\"font-weight: 400;\">que permite que voc\u00ea modifique uma parte do documento.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Modificar um grupo de usu\u00e1rios com as chaves \"73892\", \"47212\" e \"90491\"<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Sim<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Isso pode exigir v\u00e1rias opera\u00e7\u00f5es de valor-chave, mas ainda assim pode ser mais r\u00e1pido do que usar um <em>SQL <\/em><\/span><em><span style=\"font-weight: 400;\">SELECT ... WHERE ... IN<\/span><\/em><span style=\"font-weight: 400;\"> consulta.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Modificar todos os endere\u00e7os para usar \"OH\" em vez de \"Ohio\"<\/span><\/td>\n<td><span style=\"font-weight: 400;\">N\u00e3o<\/span><\/td>\n<td><span style=\"font-weight: 400;\">O estado do usu\u00e1rio \u00e9 provavelmente um atributo \"secund\u00e1rio\", n\u00e3o uma chave (v\u00e1rios usu\u00e1rios podem ser de Ohio). Esse \u00e9 um bom caso de uso para um SQL++ <\/span><span style=\"font-weight: 400;\">ATUALIZA\u00c7\u00c3O<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Como esse endpoint s\u00f3 precisa adicionar ou alterar um \u00fanico item da lista de desejos, vamos usar a API de valor-chave.<\/span><\/p>\n<h2><b>Escreva um ponto de extremidade CRUD CreateOrEdit<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Antes de come\u00e7armos a codificar, \u00e9 aconselh\u00e1vel pensar se <em>CriarOuEditar<\/em> deve ser um \u00fanico ponto de extremidade ou dividido em um <em>Criar<\/em> e um ponto de extremidade <em>Editar<\/em> endpoint. Para esse aplicativo de lista de desejos muito simples, n\u00e3o h\u00e1 valida\u00e7\u00e3o, autentica\u00e7\u00e3o ou outras preocupa\u00e7\u00f5es transversais a todo o sistema. No entanto, em um sistema de produ\u00e7\u00e3o, \"adicionar\" dados e \"atualizar\" dados podem muito bem seguir regras comerciais diferentes e exigir permiss\u00f5es diferentes. Nesse caso, talvez voc\u00ea queira dividir as opera\u00e7\u00f5es em dois endpoints.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Por enquanto, vamos come\u00e7ar com um \u00fanico ponto de extremidade que usa um \"upsert\":<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">[HttpPost]\r\n[Route(\"api\/edit\")]\r\npublic async Task&lt;IActionResult&gt; CreateOrEdit(WishlistItem item)\r\n{\r\n\u00a0 \u00a0 var bucket = await _bucketProvider.GetBucketAsync(\"demo\");\r\n\u00a0 \u00a0 var collection = await bucket.CollectionAsync(\"wishlist\");\r\n\r\n\u00a0 \u00a0 var id = item.Id ?? Guid.NewGuid();\r\n\r\n\u00a0 \u00a0 await collection.UpsertAsync(id.ToString(), new\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 Name = item.Name\r\n\u00a0 \u00a0 });\r\n\r\n\u00a0 \u00a0 return Ok(new { success = true});\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">Assim como o ponto de extremidade do SQL++, esse ponto de extremidade examina <\/span><em><span style=\"font-weight: 400;\">Id<\/span><\/em><span style=\"font-weight: 400;\"> para determinar se isso \u00e9 uma \"cria\u00e7\u00e3o\" ou uma \"atualiza\u00e7\u00e3o\".<\/span><\/p>\n<p><span style=\"font-weight: 400;\">O <\/span><em><span style=\"font-weight: 400;\">UpsertAsync<\/span><\/em><span style=\"font-weight: 400;\"> A fun\u00e7\u00e3o ir\u00e1:<\/span><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Criar um novo documento com <\/span><em><span style=\"font-weight: 400;\">id.ToString()<\/span><\/em><span style=\"font-weight: 400;\"> como a chave<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Modificar um documento existente com uma chave de <\/span><em><span style=\"font-weight: 400;\">id.ToString()<\/span><\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Em ambos os casos, quando esse endpoint terminar de ser executado, voc\u00ea ter\u00e1 um documento JSON como <\/span><em><span style=\"font-weight: 400;\">{ \"name\" = \"nome do item da lista de desejos\"}<\/span><\/em><span style=\"font-weight: 400;\"> e um GUID como chave (tecnicamente, todas as chaves no Couchbase s\u00e3o strings, mas sabemos que se trata de uma string GUID).<\/span><\/p>\n<p><strong>Observa\u00e7\u00e3o:\u00a0<\/strong><span style=\"font-weight: 400;\">Uma diferen\u00e7a sutil entre as duas APIs \u00e9 que o <\/span><em><span style=\"font-weight: 400;\">UPSERT<\/span><\/em><span style=\"font-weight: 400;\"> s\u00f3 alterar\u00e1 o \u00fanico campo (<\/span><em><span style=\"font-weight: 400;\">nome<\/span><\/em><span style=\"font-weight: 400;\">), enquanto o m\u00e9todo de valor-chave <\/span><em><span style=\"font-weight: 400;\">UpsertAsync<\/span><\/em><span style=\"font-weight: 400;\"> alterar\u00e1 o documento inteiro (que \u00e9 apenas <\/span><em><span style=\"font-weight: 400;\">nome<\/span><\/em><span style=\"font-weight: 400;\"> por enquanto).<\/span><\/p>\n<h2><b style=\"color: #343e47; font-family: Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 50px;\">ASP.NET CRUD em a\u00e7\u00e3o<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Inicie seu aplicativo no Visual Studio com CTRL+F5, e voc\u00ea ver\u00e1 alguns novos pontos de extremidade aparecerem na interface do usu\u00e1rio do OpenAPI\/Swagger:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-13501\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/06\/swagger-ui-endpoints.png\" alt=\"ASP.NET endpoints showing in Swagger UI\" width=\"787\" height=\"515\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/swagger-ui-endpoints.png 787w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/swagger-ui-endpoints-300x196.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/swagger-ui-endpoints-768x503.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/swagger-ui-endpoints-20x13.png 20w\" sizes=\"auto, (max-width: 787px) 100vw, 787px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Do ponto de vista de um consumidor de API, ambos <\/span><em><span style=\"font-weight: 400;\">\/api\/edit<\/span><\/em><span style=\"font-weight: 400;\"> e <\/span><em><span style=\"font-weight: 400;\">\/api\/editWithSql<\/span><\/em><span style=\"font-weight: 400;\"> funcionar\u00e3o da mesma forma. Experimente uma vez deixando a ID em branco para criar um novo item e, em seguida, tente novamente com uma ID conhecida (use <\/span><span style=\"font-weight: 400;\"><em>\/api\/getall<\/em><\/span><span style=\"font-weight: 400;\">\u00a0se voc\u00ea precisar obter uma identifica\u00e7\u00e3o) e observe o que acontece e o que muda.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Por exemplo, adicionei um novo item \"Digital Photo Frame\", deixando o ID em branco (meu c\u00f3digo .NET gerou \"<em>1c3de2e7-70ea-4ee2-803b-425bbf6251cb<\/em>\" para mim), e atualizei o item com o ID de \"<em>2dab198b-1836-4409-9bdf-17275a2b2462<\/em>\" para ter o nome de \"Skyline Chili 2XL T-Shirt\". Aqui est\u00e3o os resultados, conforme vistos na interface do usu\u00e1rio do Couchbase Capella:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-13502\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/06\/couchbase-capella-ui-asp.net-project.png\" alt=\"Couchbase Capella UI showing ASP.NET project documents\" width=\"872\" height=\"463\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/couchbase-capella-ui-asp.net-project.png 872w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/couchbase-capella-ui-asp.net-project-300x159.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/couchbase-capella-ui-asp.net-project-768x408.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/couchbase-capella-ui-asp.net-project-818x434.png 818w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/06\/couchbase-capella-ui-asp.net-project-20x11.png 20w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\" \/><\/p>\n<h2><b>O que vem a seguir?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">O projeto ASP.NET Core est\u00e1 conectado ao Couchbase Capella e agora est\u00e1 criando\/atualizando (\"upserting\") dados com valor-chave (recomendado) ou SQL++ (n\u00e3o recomendado para essa situa\u00e7\u00e3o espec\u00edfica).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Na pr\u00f3xima postagem do blog, completaremos o CRUD com \"D\" de \"delete\".<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Nesse meio tempo, voc\u00ea deve:<\/span><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/cloud.couchbase.com\/sign-up\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Inscreva-se para um teste gratuito do Capella<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Confira o <\/span><a href=\"https:\/\/cloud.couchbase.com\/sign-up\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Couchbase Playground para .NET<\/span><\/a><span style=\"font-weight: 400;\"> exemplos que voc\u00ea pode executar diretamente no navegador.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>ASP.NET CRUD apps include interaction with data that consists of create, read, update, and delete. In part 1, we setup a basic ASP.NET Core project. In part 2, we added the first read endpoint, using a SQL++ query against wishlist [&hellip;]<\/p>","protected":false},"author":71,"featured_media":12603,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1811,10126,10127,2225,1816,2201],"tags":[2821],"ppma_author":[8937],"class_list":["post-13499","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-asp-dotnet","category-c-sharp","category-cloud","category-couchbase-server","category-tools-sdks","tag-dbaas"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.0 (Yoast SEO v26.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ASP.NET Core CRUD with NoSQL: Part 4 - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"In this post we look at the U in CRUD that stands for UPDATE, and we build an ASP.NET Core CURD endpoint that uses UPSERT in a SQL++ query.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-nosql-part-4\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ASP.NET Core CRUD with NoSQL: Part 4\" \/>\n<meta property=\"og:description\" content=\"In this post we look at the U in CRUD that stands for UPDATE, and we build an ASP.NET Core CURD endpoint that uses UPSERT in a SQL++ query.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-nosql-part-4\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-28T21:33:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:51:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1707\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Matthew Groves\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mgroves\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matthew Groves\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/\"},\"author\":{\"name\":\"Matthew Groves\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\"},\"headline\":\"ASP.NET Core CRUD with NoSQL: Part 4\",\"datePublished\":\"2022-06-28T21:33:16+00:00\",\"dateModified\":\"2025-06-14T04:51:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/\"},\"wordCount\":870,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg\",\"keywords\":[\"dbaas\"],\"articleSection\":[\".NET\",\"ASP.NET\",\"C#\",\"Couchbase Capella\",\"Couchbase Server\",\"Tools &amp; SDKs\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/\",\"name\":\"ASP.NET Core CRUD with NoSQL: Part 4 - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg\",\"datePublished\":\"2022-06-28T21:33:16+00:00\",\"dateModified\":\"2025-06-14T04:51:46+00:00\",\"description\":\"In this post we look at the U in CRUD that stands for UPDATE, and we build an ASP.NET Core CURD endpoint that uses UPSERT in a SQL++ query.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg\",\"width\":2560,\"height\":1707,\"caption\":\"Couchbase ASP.NET Core tutorial\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ASP.NET Core CRUD with NoSQL: Part 4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\",\"name\":\"Matthew Groves\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"caption\":\"Matthew Groves\"},\"description\":\"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.\",\"sameAs\":[\"https:\/\/crosscuttingconcerns.com\",\"https:\/\/x.com\/mgroves\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/pt\/author\/matthew-groves\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"ASP.NET Core CRUD with NoSQL: Part 4 - The Couchbase Blog","description":"Nesta postagem, examinamos o U em CRUD, que significa UPDATE, e criamos um ponto de extremidade CURD do ASP.NET Core que usa UPSERT em uma consulta SQL++.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-nosql-part-4\/","og_locale":"pt_BR","og_type":"article","og_title":"ASP.NET Core CRUD with NoSQL: Part 4","og_description":"In this post we look at the U in CRUD that stands for UPDATE, and we build an ASP.NET Core CURD endpoint that uses UPSERT in a SQL++ query.","og_url":"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-nosql-part-4\/","og_site_name":"The Couchbase Blog","article_published_time":"2022-06-28T21:33:16+00:00","article_modified_time":"2025-06-14T04:51:46+00:00","og_image":[{"width":2560,"height":1707,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg","type":"image\/jpeg"}],"author":"Matthew Groves","twitter_card":"summary_large_image","twitter_creator":"@mgroves","twitter_misc":{"Written by":"Matthew Groves","Est. reading time":"5 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/"},"author":{"name":"Matthew Groves","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58"},"headline":"ASP.NET Core CRUD with NoSQL: Part 4","datePublished":"2022-06-28T21:33:16+00:00","dateModified":"2025-06-14T04:51:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/"},"wordCount":870,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg","keywords":["dbaas"],"articleSection":[".NET","ASP.NET","C#","Couchbase Capella","Couchbase Server","Tools &amp; SDKs"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/","url":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/","name":"ASP.NET Core CRUD with NoSQL: Part 4 - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg","datePublished":"2022-06-28T21:33:16+00:00","dateModified":"2025-06-14T04:51:46+00:00","description":"Nesta postagem, examinamos o U em CRUD, que significa UPDATE, e criamos um ponto de extremidade CURD do ASP.NET Core que usa UPSERT em uma consulta SQL++.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/12\/hannah-wei-aso6SYJZGps-unsplash-scaled.jpg","width":2560,"height":1707,"caption":"Couchbase ASP.NET Core tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/asp-net-core-crud-nosql-part-4\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"ASP.NET Core CRUD with NoSQL: Part 4"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"Blog do Couchbase","description":"Couchbase, o banco de dados NoSQL","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"Blog do Couchbase","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58","name":"Matthew Groves","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54","url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","caption":"Matthew Groves"},"description":"Matthew D. Groves \u00e9 um cara que adora programar. N\u00e3o importa se \u00e9 C#, jQuery ou PHP: ele enviar\u00e1 solicita\u00e7\u00f5es de pull para qualquer coisa. Ele tem programado profissionalmente desde que escreveu um aplicativo de ponto de venda QuickBASIC para a pizzaria de seus pais nos anos 90. Atualmente, ele trabalha como gerente s\u00eanior de marketing de produtos da Couchbase. Seu tempo livre \u00e9 passado com a fam\u00edlia, assistindo aos Reds e participando da comunidade de desenvolvedores. Ele \u00e9 autor de AOP in .NET, Pro Microservices in .NET, autor da Pluralsight e Microsoft MVP.","sameAs":["https:\/\/crosscuttingconcerns.com","https:\/\/x.com\/mgroves"],"url":"https:\/\/www.couchbase.com\/blog\/pt\/author\/matthew-groves\/"}]}},"authors":[{"term_id":8937,"user_id":71,"is_guest":0,"slug":"matthew-groves","display_name":"Matthew Groves","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","author_category":"","last_name":"Groves","first_name":"Matthew","job_title":"","user_url":"https:\/\/crosscuttingconcerns.com","description":"Matthew D. Groves \u00e9 um cara que adora programar.  N\u00e3o importa se \u00e9 C#, jQuery ou PHP: ele enviar\u00e1 solicita\u00e7\u00f5es de pull para qualquer coisa.  Ele tem programado profissionalmente desde que escreveu um aplicativo de ponto de venda QuickBASIC para a pizzaria de seus pais nos anos 90.  Atualmente, ele trabalha como gerente s\u00eanior de marketing de produtos da Couchbase. Seu tempo livre \u00e9 passado com a fam\u00edlia, assistindo aos Reds e participando da comunidade de desenvolvedores.  Ele \u00e9 autor de AOP in .NET, Pro Microservices in .NET, autor da Pluralsight e Microsoft MVP."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/13499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/comments?post=13499"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/13499\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media\/12603"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=13499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=13499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=13499"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/ppma_author?post=13499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}