{"id":13087,"date":"2022-04-18T11:02:34","date_gmt":"2022-04-18T18:02:34","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=13087"},"modified":"2025-06-13T20:56:46","modified_gmt":"2025-06-14T03:56:46","slug":"asp-net-crud-nosql-part-2","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-crud-nosql-part-2\/","title":{"rendered":"CRUD do ASP.NET Core com NoSQL: Parte 2"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">CRUD significa Create (criar), Read (ler), Update (atualizar) e Delete (excluir). Na parte 2, veremos o R para leitura e criaremos um ponto de extremidade do ASP.NET Core para ler dados do Couchbase usando SQL.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Certifique-se de ler <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-core-crud-with-nosql-part-1\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Parte 1 desta s\u00e9rie<\/span><\/a><span style=\"font-weight: 400;\">que abrange a instala\u00e7\u00e3o e a configura\u00e7\u00e3o de seu projeto ASP.NET Core \"wishlist\".<\/span><\/p>\n<h2><b>SQL++ para ler<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">O Couchbase \u00e9 \u00fanico entre os bancos de dados NoSQL, pois oferece suporte a um <\/span><a href=\"https:\/\/cloud.couchbase.com\/sign-up\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">implementa\u00e7\u00e3o completa de SQL<\/span><\/a><span style=\"font-weight: 400;\"> (chamado SQL++, tamb\u00e9m conhecido como N1QL) para consultar dados JSON.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">O SQL++ n\u00e3o \u00e9 uma linguagem \"semelhante ao SQL\" dilu\u00edda. Com o SQL++, voc\u00ea tem <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/join.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">JOINs<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/with.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">CTEs\/com<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/update.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">ATUALIZA\u00c7\u00c3O<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/insert.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">INSERIR<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/delete.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">DELETE<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/merge.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">MERGE<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/groupby.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">agrega\u00e7\u00e3o\/GROUP BY<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/begin-transaction.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">BEGIN\/COMMIT\/ROLLBACK<\/span><\/a><span style=\"font-weight: 400;\">e muito mais.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Al\u00e9m disso (o \"++\"), voc\u00ea tamb\u00e9m tem recursos para lidar com dados JSON, como <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/datatypes.html#datatype-missing\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">FALTANDO<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/nest.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">NEST<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/arrayfun.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Fun\u00e7\u00f5es ARRAY_*<\/span><\/a><span style=\"font-weight: 400;\">, <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/objectfun.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Fun\u00e7\u00f5es OBJECT_*<\/span><\/a><span style=\"font-weight: 400;\">e muito mais.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Para este aplicativo CRUD simples, usaremos um aplicativo SQL++ <\/span><span style=\"font-weight: 400;\">SELECIONAR<\/span><span style=\"font-weight: 400;\"> consulta (e \u00edndice) para retornar <\/span><b>todos<\/b><span style=\"font-weight: 400;\"> itens da minha lista de desejos.<\/span><\/p>\n<h2><b>Escrevendo sua primeira consulta SQL++<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Primeiro, vamos tentar escrever uma consulta SQL++ para obter todos os itens da lista de desejos diretamente no <\/span><a href=\"https:\/\/docs.couchbase.com\/cloud\/clusters\/query-service\/query-workbench.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Capella Query Workbench<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Para come\u00e7ar, tente:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:tsql decode:true\">SELECT * FROM demo._default.wishlist;<\/pre>\n<p><span style=\"font-weight: 400;\">Ao fazer isso, voc\u00ea dever\u00e1 receber uma mensagem de erro. Algo como:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">`no index available on keyspace default:demo._default.wishlist that matches your query. Use CREATE PRIMARY INDEX` ...<\/pre>\n<p><span style=\"font-weight: 400;\">Esse \u00e9 o comportamento esperado. (A maioria das) consultas SQL++ no Couchbase n\u00e3o ser\u00e1 executada a menos que haja pelo menos um \u00edndice dispon\u00edvel para elas.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">N\u00e3o tem problema. Crie um <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/createprimaryindex.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">\u00cdNDICE PRIM\u00c1RIO<\/span><\/a><span style=\"font-weight: 400;\"> com um comando como este:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:tsql decode:true\">CREATE PRIMARY INDEX `ix_wishlist` ON `demo`.`_default`.`wishlist`<\/pre>\n<p><span style=\"font-weight: 400;\">Em geral, os \u00edndices prim\u00e1rios n\u00e3o devem ser usados em um ambiente de produ\u00e7\u00e3o t\u00edpico, mas s\u00e3o muito \u00fateis em um ambiente de desenvolvimento, pois garantem que <\/span><b>qualquer<\/b><span style=\"font-weight: 400;\"> A consulta SQL++ ser\u00e1 executada na cole\u00e7\u00e3o indexada (embora n\u00e3o seja t\u00e3o eficiente quanto uma cole\u00e7\u00e3o indexada corretamente). Quando voc\u00ea come\u00e7ar a criar consultas SQL++ mais complexas, poder\u00e1 usar a fun\u00e7\u00e3o <\/span><a href=\"https:\/\/docs.couchbase.com\/cloud\/clusters\/query-service\/query-workbench.html#index-advisor\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Bot\u00e3o \"Advise\" (Aconselhar) no Query Workbench<\/span><\/a><span style=\"font-weight: 400;\"> para obter sugest\u00f5es de \u00edndices mais eficientes a serem criados (e voc\u00ea deve evitar usar <\/span><span style=\"font-weight: 400;\">SELECT *<\/span><span style=\"font-weight: 400;\"> sempre que puder \ud83d\ude06).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Depois de criar o \u00edndice, tente novamente o procedimento acima <\/span><span style=\"font-weight: 400;\">SELECIONAR<\/span><span style=\"font-weight: 400;\"> novamente, e os resultados dever\u00e3o ter a seguinte apar\u00eancia:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:tsql decode:true\">[\r\n\u00a0 {\r\n\u00a0 \u00a0 \"wishlist\": {\r\n\u00a0 \u00a0 \u00a0 \"name\": \"Skyline Chili T-Shirt\"\r\n\u00a0 \u00a0 }\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0 \u00a0 \"wishlist\": {\r\n\u00a0 \u00a0 \u00a0 \"name\": \"Joey Votto jersey\"\r\n\u00a0 \u00a0 }\r\n\u00a0 }\r\n]<\/pre>\n<p><span style=\"font-weight: 400;\">Quase l\u00e1. Tente imaginar essa matriz de objetos sendo serializada em um C# <\/span><em><span style=\"font-weight: 400;\">Lista<\/span><\/em><span style=\"font-weight: 400;\">. Isso n\u00e3o funcionaria muito bem, porque os objetos s\u00e3o aninhados com o nome da cole\u00e7\u00e3o. Por isso, adquiri o h\u00e1bito de colocar aliases nas cole\u00e7\u00f5es, assim:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:tsql decode:true\">SELECT w.* FROM demo._default.wishlist w;<\/pre>\n<p><span style=\"font-weight: 400;\">O que produz o resultado:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:js decode:true\">[\r\n\u00a0 {\r\n\u00a0 \u00a0 \"name\": \"Skyline Chili T-Shirt\"\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0 \u00a0 \"name\": \"Joey Votto jersey\"\r\n\u00a0 }\r\n]<\/pre>\n<p><span style=\"font-weight: 400;\">Parece bom, mas ainda est\u00e1 faltando alguma coisa. Onde est\u00e3o os GUIDs que usamos para as chaves do documento? O Couchbase n\u00e3o os armazena como dados; ele os armazena como <\/span><b>metadados<\/b><span style=\"font-weight: 400;\">. O SQL++ fornece o <\/span><em><span style=\"font-weight: 400;\">META()<\/span><\/em><span style=\"font-weight: 400;\"> para consultar metadados. Usar <\/span><em><span style=\"font-weight: 400;\">META().id<\/span><\/em><span style=\"font-weight: 400;\"> assim:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:tsql decode:true\">SELECT META(w).id, w.* FROM demo._default.wishlist w;<\/pre>\n<p><span style=\"font-weight: 400;\">E isso finalmente nos d\u00e1 um resultado de:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:js decode:true\">[\r\n\u00a0 {\r\n\u00a0 \u00a0 \"id\": \"2dab198b-1836-4409-9bdf-17275a2b2462\",\r\n\u00a0 \u00a0 \"name\": \"Skyline Chili T-Shirt\"\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0 \u00a0 \"id\": \"31c9cc33-8dfe-440c-bd1b-bb038939d2e0\",\r\n\u00a0 \u00a0 \"name\": \"Joey Votto jersey\"\r\n\u00a0 }\r\n]<\/pre>\n<p><span style=\"font-weight: 400;\">Isso ser\u00e1 serializado de forma adequada em <\/span><em><span style=\"font-weight: 400;\">Item da lista de desejos<\/span><\/em><span style=\"font-weight: 400;\"> usando a classe criada na parte 1.<\/span><\/p>\n<h2><b>Usando o SQL++ no ASP.NET Core<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Vamos colocar a consulta SQL++ que acabamos de escrever em um endpoint ASP.NET Core.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Em <em>GiftsController<\/em>crie um ponto de extremidade chamado <em>Obter tudo<\/em>:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:c# decode:true\">[HttpGet]\r\n[Route(\"api\/getall\")]\r\npublic async Task&lt;IActionResult&gt; GetAll()\r\n{\r\n\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">Para executar o SQL++, precisamos obter um objeto do tipo <\/span><span style=\"font-weight: 400;\">Aglomerado<\/span><span style=\"font-weight: 400;\">. O SQL++ \u00e9 executado no n\u00edvel do cluster (e n\u00e3o do bucket, do escopo ou da cole\u00e7\u00e3o, pois pode ser necess\u00e1rio <\/span><span style=\"font-weight: 400;\">JUNTAR<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">UNI\u00c3O<\/span><span style=\"font-weight: 400;\"> entre eles). Poder\u00edamos voltar e adicionar <\/span><a href=\"https:\/\/docs.couchbase.com\/dotnet-sdk\/current\/howtos\/managing-connections.html#injecting-the-couchbase-cluster\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Provedor de cluster<\/span><\/a><span style=\"font-weight: 400;\"> como um par\u00e2metro do construtor. Se esse endpoint fosse funcionar apenas com o SQL++, seria uma boa ideia. No entanto, vamos nos ater ao que criamos na parte 1. Temos um objeto do tipo <\/span><em><span style=\"font-weight: 400;\">Provedor de balde<\/span><\/em><span style=\"font-weight: 400;\">. A partir desse objeto, voc\u00ea pode obter um objeto do tipo <\/span><span style=\"font-weight: 400;\">Aglomerado<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:c# decode:true\">[HttpGet]\r\n[Route(\"api\/getall\")]\r\npublic async Task&lt;IActionResult&gt; GetAll()\r\n{\r\n  var bucket = await _bucketProvider.GetBucketAsync(\"demo\");\r\n  var cluster = bucket.Cluster;\r\n\r\n  \/\/ ... snip ...\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">A <\/span><span style=\"font-weight: 400;\">agrupamento<\/span><span style=\"font-weight: 400;\"> \u00e9 como o ASP.NET Core interagir\u00e1 com um cluster do Couchbase de v\u00e1rias maneiras. Por enquanto, estamos interessados em seu objeto <\/span><em><span style=\"font-weight: 400;\">QueryAsync<\/span><\/em><span style=\"font-weight: 400;\"> m\u00e9todo:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:c# decode:true\">[HttpGet]\r\n[Route(\"api\/getall\")]\r\npublic async Task&lt;IActionResult&gt; GetAll()\r\n{\r\n  var bucket = await _bucketProvider.GetBucketAsync(\"demo\");\r\n  var cluster = bucket.Cluster;\r\n\r\n  var result = await cluster.QueryAsync&lt;WishlistItem&gt;(\r\n    \"SELECT META(w).id, w.* FROM demo._default.wishlist w;\"\r\n  );\r\n\r\n  return Ok(result);\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">Certifique-se de que voc\u00ea tenha o seguinte <\/span><span style=\"font-weight: 400;\">usando<\/span><span style=\"font-weight: 400;\"> na parte superior de seu <em>GiftsController.cs<\/em> file:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:c# decode:true\">using AspNetCoreTutorial.Models;\r\nusing Microsoft.AspNetCore.Mvc;\r\nusing Couchbase;\r\nusing Couchbase.Query;\r\nusing Couchbase.Extensions.DependencyInjection;<\/pre>\n<p><span style=\"font-weight: 400;\">Mais um aspecto a ser observado. Ao executar o SQL++, h\u00e1 uma s\u00e9rie de <\/span><a href=\"https:\/\/docs.couchbase.com\/dotnet-sdk\/current\/howtos\/n1ql-queries-with-sdk.html#scan-consistency\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Op\u00e7\u00f5es de consist\u00eancia (digitaliza\u00e7\u00e3o)<\/span><\/a><span style=\"font-weight: 400;\">. O padr\u00e3o \u00e9 <\/span><em><span style=\"font-weight: 400;\">ScanConsistency.NotBounded<\/span><\/em><span style=\"font-weight: 400;\">. Essa configura\u00e7\u00e3o significa que o mecanismo de consulta <\/span><b>n\u00e3o<\/b><span style=\"font-weight: 400;\"> esperar que os \u00edndices terminem de ser atualizados antes de retornar os resultados. Essa \u00e9 a op\u00e7\u00e3o de melhor desempenho. Entretanto, em algumas situa\u00e7\u00f5es, voc\u00ea desejar\u00e1 uma consist\u00eancia de \u00edndice mais forte. O Couchbase fornece <\/span><em><span style=\"font-weight: 400;\">RequestPlus<\/span><\/em><span style=\"font-weight: 400;\"> e <\/span><em><span style=\"font-weight: 400;\">AtPlus<\/span><\/em><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><b>Experimente o ponto de extremidade do ASP.NET Core<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">No Visual Studio, <strong>Ctrl+F5<\/strong> iniciar\u00e1 o aplicativo. Voc\u00ea dever\u00e1 ver uma p\u00e1gina OpenAPI \/ Swagger no navegador.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-13088\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/04\/image1-1.png\" alt=\"ASP.NET app reading from Couchbase\" width=\"827\" height=\"452\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image1-1.png 827w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image1-1-300x164.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image1-1-768x420.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image1-1-20x11.png 20w\" sizes=\"auto, (max-width: 827px) 100vw, 827px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">(Ignorar <em>Previs\u00e3o do tempo<\/em>que veio com o modelo do Visual Studio).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Clique no endpoint para experiment\u00e1-lo. N\u00e3o h\u00e1 par\u00e2metros a serem especificados, portanto, basta clicar em <strong>Executar<\/strong>.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-13089\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/04\/image2-1.png\" alt=\"Testing an ASP.NET endpoint and Couchbase\" width=\"806\" height=\"809\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image2-1.png 806w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image2-1-300x301.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image2-1-150x150.png 150w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image2-1-768x771.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image2-1-65x65.png 65w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image2-1-50x50.png 50w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/image2-1-20x20.png 20w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Agora voc\u00ea tem o \"R\" de CRUD no lugar.<\/span><\/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 est\u00e1 lendo dados via SQL++.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Na pr\u00f3xima postagem do blog, criaremos outro endpoint de \"leitura\". Em vez de SQL++, analisaremos outra maneira mais r\u00e1pida de acessar e ler dados.<\/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>CRUD stands for Create, Read, Update, and Delete. In part 2, we\u2019ll look at R for Read, and build an ASP.NET Core endpoint to read data from Couchbase using SQL. Make sure to read part 1 of this series, which [&hellip;]<\/p>","protected":false},"author":71,"featured_media":13090,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1811,10126,10127,1816],"tags":[],"ppma_author":[8937],"class_list":["post-13087","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-asp-dotnet","category-c-sharp","category-couchbase-server"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ASP.NET Core CRUD with NoSQL: Part 2 - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"In this post we look at the R in CRUD that stands for Read, and we build an ASP.NET Core endpoint to read data from Couchbase using SQL.\" \/>\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-crud-nosql-part-2\/\" \/>\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 2\" \/>\n<meta property=\"og:description\" content=\"In this post we look at the R in CRUD that stands for Read, and we build an ASP.NET Core endpoint to read data from Couchbase using SQL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-crud-nosql-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-18T18:02:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T03:56:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-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=\"4 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-crud-nosql-part-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/\"},\"author\":{\"name\":\"Matthew Groves\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\"},\"headline\":\"ASP.NET Core CRUD with NoSQL: Part 2\",\"datePublished\":\"2022-04-18T18:02:34+00:00\",\"dateModified\":\"2025-06-14T03:56:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/\"},\"wordCount\":801,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-scaled.jpg\",\"articleSection\":[\".NET\",\"ASP.NET\",\"C#\",\"Couchbase Server\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/\",\"name\":\"ASP.NET Core CRUD with NoSQL: Part 2 - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-scaled.jpg\",\"datePublished\":\"2022-04-18T18:02:34+00:00\",\"dateModified\":\"2025-06-14T03:56:46+00:00\",\"description\":\"In this post we look at the R in CRUD that stands for Read, and we build an ASP.NET Core endpoint to read data from Couchbase using SQL.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-scaled.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-scaled.jpg\",\"width\":2560,\"height\":1707,\"caption\":\"ASP.NET app tutorial to read from Couchbase NoSQL\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#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 2\"}]},{\"@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 2 - The Couchbase Blog","description":"Nesta postagem, analisamos o R em CRUD, que significa Read (leitura), e criamos um ponto de extremidade do ASP.NET Core para ler dados do Couchbase usando 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-crud-nosql-part-2\/","og_locale":"pt_BR","og_type":"article","og_title":"ASP.NET Core CRUD with NoSQL: Part 2","og_description":"In this post we look at the R in CRUD that stands for Read, and we build an ASP.NET Core endpoint to read data from Couchbase using SQL.","og_url":"https:\/\/www.couchbase.com\/blog\/pt\/asp-net-crud-nosql-part-2\/","og_site_name":"The Couchbase Blog","article_published_time":"2022-04-18T18:02:34+00:00","article_modified_time":"2025-06-14T03:56:46+00:00","og_image":[{"width":2560,"height":1707,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-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":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/"},"author":{"name":"Matthew Groves","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58"},"headline":"ASP.NET Core CRUD with NoSQL: Part 2","datePublished":"2022-04-18T18:02:34+00:00","dateModified":"2025-06-14T03:56:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/"},"wordCount":801,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-scaled.jpg","articleSection":[".NET","ASP.NET","C#","Couchbase Server"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/","url":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/","name":"ASP.NET Core CRUD with NoSQL: Part 2 - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-scaled.jpg","datePublished":"2022-04-18T18:02:34+00:00","dateModified":"2025-06-14T03:56:46+00:00","description":"Nesta postagem, analisamos o R em CRUD, que significa Read (leitura), e criamos um ponto de extremidade do ASP.NET Core para ler dados do Couchbase usando SQL.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-scaled.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/04\/asp-net-couchbase-read-app-part2-scaled.jpg","width":2560,"height":1707,"caption":"ASP.NET app tutorial to read from Couchbase NoSQL"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/asp-net-crud-nosql-part-2\/#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 2"}]},{"@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\/13087","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=13087"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/13087\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media\/13090"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=13087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=13087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=13087"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/ppma_author?post=13087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}