jaykob
یک شنبه 22 مرداد 1396, 23:31 عصر
سلام
من در زمان ویرایش که از کد زیر استفاده می کنم :
_db.Entry(MyModel).State = EntityState.Modified;
_db.SaveChanges();
از این کد بارها استفاده کردم و همه چیز مرتب بوده . اما داخل یک پروژه هر چی تلاش می کنم از این کد برای ویرایش استفاده می کنم خطای زیر رو می گیریم . سرچ هم کردم تقریبا هر چی راهکار هم تست کردم همین خطا هستش . از ef code first و flunet api استفاده کردم . ممنون می شم راهنمایی کنید:
Attaching an entity of type '' 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.
تشکر
من در زمان ویرایش که از کد زیر استفاده می کنم :
_db.Entry(MyModel).State = EntityState.Modified;
_db.SaveChanges();
از این کد بارها استفاده کردم و همه چیز مرتب بوده . اما داخل یک پروژه هر چی تلاش می کنم از این کد برای ویرایش استفاده می کنم خطای زیر رو می گیریم . سرچ هم کردم تقریبا هر چی راهکار هم تست کردم همین خطا هستش . از ef code first و flunet api استفاده کردم . ممنون می شم راهنمایی کنید:
Attaching an entity of type '' 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.
تشکر