﻿
{"id":9948,"date":"2018-12-02T23:28:56","date_gmt":"2018-12-02T23:28:56","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=9948"},"modified":"2018-12-02T23:28:56","modified_gmt":"2018-12-02T23:28:56","slug":"asp-net-core-the-instance-of-entity-type-x-cannot-be-tracked-because-another-instance-of-this-type-with-the-same-key-is-already-being-tracked-hatasi-ve-cozumu","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/asp-net-core-the-instance-of-entity-type-x-cannot-be-tracked-because-another-instance-of-this-type-with-the-same-key-is-already-being-tracked-hatasi-ve-cozumu\/","title":{"rendered":"Asp.NET Core &#8211; &#8220;The Instance Of Entity Type &#8216;X&#8217; Cannot Be Tracked Because Another Instance Of This Type With The Same Key Is Already Being Tracked&#8221; Hatas\u0131 ve \u00c7\u00f6z\u00fcm\u00fc"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Asp.NET Core framework&#8217;\u00fc temelinde geli\u015ftirilen bir web projesinde, i\u00e7erisinde kendi tipinden ba\u015fka bir anahtar de\u011fere ba\u011fl\u0131 olan ya da bir ba\u015fka deyi\u015fle i\u00e7erisinde kendi kendine foreign key ba\u011flant\u0131s\u0131 olan entity&#8217;den t\u00fcretilmi\u015f datalar \u00fczerinde bir g\u00fcncelleme i\u015flemi yapmaya \u00e7al\u0131\u015f\u0131ld\u0131\u011f\u0131 zaman a\u015fa\u011f\u0131daki olas\u0131 hatayla kar\u015f\u0131la\u015f\u0131lmas\u0131 muhtemeldir;<\/p>\n<blockquote><p><strong><span style=\"color: #008000;\"><em>&#8220;The instance of entity type &#8216;X&#8217; cannot be tracked because another instance with the same key value for {&#8216;Id&#8217;} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using &#8216;DbContextOptionsBuilder.EnableSensitiveDataLogging&#8217; to see the conflicting key values.'&#8221;<\/em><\/span><\/strong><\/p><\/blockquote>\n<p>\u0130\u015fte b\u00f6yle bir durumda ilgili hatay\u0131 a\u015fabilmek i\u00e7in uygulamada kullan\u0131lan &#8220;Context&#8221; s\u0131n\u0131f\u0131n\u0131n nesnesi \u00fczerinden a\u015fa\u011f\u0131daki uygulamay\u0131 ger\u00e7ekle\u015ftirmek olduk\u00e7a yeterli olacakt\u0131r;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nDbContext.Entry&lt;X&gt;(model).State = Microsoft.EntityFrameworkCore.EntityState.Modified;\r\n<\/pre>\n<p>Generic olan &#8220;Entry&#8221; metoduna verilen generic tip ile uyumlu &#8220;model&#8221; nesnesinin &#8220;State&#8221; de\u011ferinin &#8220;Modified&#8221; olarak belirtilmesi, hatan\u0131n temel sebebi olan i\u00e7 i\u00e7e ili\u015fkisel duruma ra\u011fmen veri \u00fczerinde de\u011fi\u015fikli\u011fe izin verecek ve ilgili hatay\u0131 ortadan kald\u0131racakt\u0131r.<\/p>\n<p>Faydalanman\u0131z 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, Asp.NET Core framework&#8217;\u00fc temelinde geli\u015ftirilen bir web projesinde, i\u00e7erisinde kendi tipinden ba\u015fka bir anahtar de\u011fere ba\u011fl\u0131 olan ya da bir ba\u015fka deyi\u015fle i\u00e7erisinde kendi kendine foreign key ba\u011flant\u0131s\u0131 olan entity&#8217;den t\u00fcretilmi\u015f datalar \u00fczerinde&#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":9596,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2668,2656,258],"tags":[2652,2704,260,849,1561],"class_list":["post-9948","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net-core-2","category-asp-net-core-2-mvc","category-hata-cozumleri","tag-asp-net-core-2","tag-asp-net-core-hata","tag-hata","tag-hata-cozumleri","tag-hata-ve-cozumleri"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/9948","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=9948"}],"version-history":[{"count":7,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/9948\/revisions"}],"predecessor-version":[{"id":9955,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/9948\/revisions\/9955"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/9596"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=9948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=9948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=9948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}