سلام .
در پروژه ام وقتی میخوام اطلاعات کاربرم رو بروز رسانی کنم این پیغام خطارو میده :
Attaching an entity of type 'DomainClasses.Models.Users' failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate.
متوجهش نمیشم . بار اول که میبینمش .
ممنونم
دلیلش اینه که change tracker روشن هستش و شما یکبار داده رو find کردید که با اینکار ef خودکار اون رو attach میکنه برای track بعدی
حالا شما اومدی دوباره خودت هم همون entity رو attach کردی و ef داره میگه که نمیتونه attach کنه چون موجود داره.
شما از متد add استفاده کن و اون قسمتی رو که Attach کردی تا entrystate رو added کنی، پاک کن.
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)