﻿
{"id":16033,"date":"2020-05-23T19:03:56","date_gmt":"2020-05-23T19:03:56","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=16033"},"modified":"2020-05-23T19:03:56","modified_gmt":"2020-05-23T19:03:56","slug":"odata-crud-islemleri","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/odata-crud-islemleri\/","title":{"rendered":"OData CRUD \u0130\u015flemleri"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>OData her ne kadar url \u00fczerinden veri kaynaklar\u0131n\u0131 sorgulama protokol\u00fc olsada temel CRUD i\u015flemlerini destekleyen niteliklerede sahiptir. \u015eimdi gelin OData ile CRUD i\u015flemlerinin nas\u0131l yap\u0131ld\u0131\u011f\u0131n\u0131 inceleyelim.<\/p>\n<p><strong>GET<\/strong><br \/>\nOData \u00fczerinden GET iste\u011fi ile veri okuma i\u015fleminde bulunabilmek i\u00e7in \u015fuana kadar \u00f6nceki makalelerde yapt\u0131\u011f\u0131m\u0131z \u00e7al\u0131\u015fmalardaki gibi bir action olu\u015fturulmas\u0131 yeterli olacakt\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class PersonelController : ODataController\r\n    {\r\n        .\r\n        .\r\n        .\r\n        &#x5B;EnableQuery]\r\n        public IActionResult Get()\r\n        {\r\n            return Ok(_northwindContext.Personeller);\r\n        }\r\n    }\r\n<\/pre>\n<p>\u00d6rnek URL : <code style=\"color:red;\"><strong>https:\/\/localhost:5001\/odata\/<span style=\"color:blue;\">personel<\/span><\/strong><\/code><\/p>\n<p>Tabi id bazl\u0131 sorgulama ile birlikte daha da \u00f6zelle\u015ftirilmi\u015f GET operasyonlar\u0131n\u0131n in\u015fas\u0131 i\u00e7in <a href=\"https:\/\/www.gencayyildiz.com\/blog\/odata-davranis-modellemesi-ve-attributelari\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u015fu<\/a> ve <a href=\"https:\/\/www.gencayyildiz.com\/blog\/odata-custom-route-yapilanmasi\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u015fu<\/a> makalelere g\u00f6z atman\u0131z\u0131 \u00f6neririm.<\/p>\n<p><strong>POST<\/strong><br \/>\nPOST i\u015flemi i\u00e7in a\u015fa\u011f\u0131daki imzalardan birinde action olu\u015fturulmas\u0131 yeterlidir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class PersonelController : ODataController\r\n    {\r\n        .\r\n        .\r\n        .\r\n        &#x5B;HttpPost]\r\n        public bool Post(&#x5B;FromBody] Personel personel)\r\n        {\r\n            _northwindContext.Personeller.Add(personel);\r\n            _northwindContext.SaveChanges();\r\n            return true;\r\n        }\r\n    }\r\n<\/pre>\n<p>ya da<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class PersonelController : ODataController\r\n    {\r\n        .\r\n        .\r\n        .\r\n        &#x5B;HttpPost]\r\n        public bool PostPersonel(&#x5B;FromBody] Personel personel)\r\n        {\r\n            _northwindContext.Personeller.Add(personel);\r\n            _northwindContext.SaveChanges();\r\n            return true;\r\n        }\r\n    }\r\n<\/pre>\n<p>\u00d6rnek URL :<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri.jpg\" alt=\"OData CRUD \u0130\u015flemleri\" width=\"802\" height=\"424\" class=\"aligncenter size-full wp-image-16041\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri.jpg 802w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri-300x159.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri-768x406.jpg 768w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><br \/>\n<strong>PUT<\/strong><br \/>\nPUT i\u015flemi i\u00e7inde a\u015fa\u011f\u0131dakine benzer imzalarda actionlar olu\u015fturulabilir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class PersonelController : ODataController\r\n    {\r\n        .\r\n        .\r\n        .\r\n        &#x5B;HttpPut]\r\n        public bool Put(&#x5B;FromODataUri] int key, &#x5B;FromBody] Personel personel)\r\n        {\r\n            personel.PersonelId = key;\r\n            _northwindContext.Entry(personel).State = Microsoft.EntityFrameworkCore.EntityState.Modified;\r\n            _northwindContext.SaveChanges();\r\n            return true;\r\n        }\r\n    }\r\n<\/pre>\n<p>ya da<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class PersonelController : ODataController\r\n    {\r\n        .\r\n        .\r\n        .\r\n        &#x5B;HttpPut]\r\n        public bool PutPersonel(&#x5B;FromODataUri] int key, &#x5B;FromBody] Personel personel)\r\n        {\r\n            personel.PersonelId = key;\r\n            _northwindContext.Entry(personel).State = Microsoft.EntityFrameworkCore.EntityState.Modified;\r\n            _northwindContext.SaveChanges();\r\n            return true;\r\n        }\r\n    }\r\n<\/pre>\n<p>\u00d6rnek URL :<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri-1.jpg\" alt=\"OData CRUD \u0130\u015flemleri\" width=\"804\" height=\"426\" class=\"aligncenter size-full wp-image-16043\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri-1.jpg 804w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri-1-300x159.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/05\/OData-CRUD-\u0130\u015flemleri-1-768x407.jpg 768w\" sizes=\"auto, (max-width: 804px) 100vw, 804px\" \/><\/a><br \/>\n<strong>DELETE<\/strong><br \/>\nDELETE i\u015flemi i\u00e7inde yukar\u0131dakilere benzer nitelikte actionlar olu\u015fturulmas\u0131 yeterlidir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class PersonelController : ODataController\r\n    {\r\n        .\r\n        .\r\n        .\r\n        &#x5B;HttpDelete]\r\n        public IActionResult Delete(&#x5B;FromODataUri] int key)\r\n        {\r\n            Personel silinecekPersonel = _northwindContext.Personeller.Find(key);\r\n            if (silinecekPersonel == null) return NotFound();\r\n            _northwindContext.Remove(silinecekPersonel);\r\n            _northwindContext.SaveChanges();\r\n            return Ok(true);\r\n        }\r\n    }\r\n<\/pre>\n<p>ya da<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class PersonelController : ODataController\r\n    {\r\n        .\r\n        .\r\n        .\r\n        &#x5B;HttpDelete]\r\n        public IActionResult DeletePersonel(&#x5B;FromODataUri] int key)\r\n        {\r\n            Personel silinecekPersonel = _northwindContext.Personeller.Find(key);\r\n            if (silinecekPersonel == null) return NotFound();\r\n            _northwindContext.Remove(silinecekPersonel);\r\n            _northwindContext.SaveChanges();\r\n            return Ok(true);\r\n        }\r\n    }\r\n<\/pre>\n<p>\u00d6rnek URL : <code style=\"color:red;\"><strong>https:\/\/localhost:5001\/odata\/<span style=\"color:blue;\">personel(10)<\/span><\/strong><\/code><\/p>\n<blockquote><p><strong style=\"color:orange;\">GET d\u0131\u015f\u0131nda POST, PUT ve DELETE fonksiyonlar\u0131n\u0131 &#8216;EnableQuery&#8217; attribute&#8217;u ile i\u015faretlemedi\u011fimize dikkatinizi \u00e7ekerim.<\/strong><\/p><\/blockquote>\n<h3>Metotlar\u0131 \u00d6zelle\u015ftirme<\/h3>\n<p>Yukar\u0131da olu\u015fturdu\u011fumuz belirli kurallardaki metotlar\u0131 k\u0131smi \u00f6zelle\u015ftirebilmek i\u00e7in <a href=\"https:\/\/www.gencayyildiz.com\/blog\/odata-davranis-modellemesi-ve-attributelari\/\" rel=\"noopener noreferrer\" target=\"_blank\">OData Davran\u0131\u015f Modellemesi ve Attributelar\u0131<\/a> makalesinde oldu\u011fu gibi &#8216;ODataRoute&#8217; attribute&#8217;u ile i\u015faretleyebilmekteyiz.<\/p>\n<p>\u00d6rne\u011fin;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        &#x5B;HttpDelete]\r\n        &#x5B;ODataRoute(&quot;personel({id})&quot;)]\r\n        public IActionResult Sil(&#x5B;FromODataUri] int id)\r\n        {\r\n            Personel silinecekPersonel = _northwindContext.Personeller.Find(id);\r\n            if (silinecekPersonel == null) return NotFound();\r\n            _northwindContext.Remove(silinecekPersonel);\r\n            _northwindContext.SaveChanges();\r\n            return Ok(true);\r\n        }\r\n<\/pre>\n<p>\u015feklinde oldu\u011fu gibi&#8230;<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, OData her ne kadar url \u00fczerinden veri kaynaklar\u0131n\u0131 sorgulama protokol\u00fc olsada temel CRUD i\u015flemlerini destekleyen niteliklerede sahiptir. \u015eimdi gelin OData ile CRUD i\u015flemlerinin nas\u0131l yap\u0131ld\u0131\u011f\u0131n\u0131 inceleyelim. GET OData \u00fczerinden GET iste\u011fi ile veri&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":15889,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3516],"tags":[3514,3532,3535,3538,3534,3537,3539,3533,3536],"class_list":["post-16033","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","tag-odata","tag-odata-crud","tag-odata-delete","tag-odata-get","tag-odata-insert","tag-odata-post","tag-odata-put","tag-odata-select","tag-odata-update"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/16033","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=16033"}],"version-history":[{"count":12,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/16033\/revisions"}],"predecessor-version":[{"id":16047,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/16033\/revisions\/16047"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/15889"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=16033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=16033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=16033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}