c# - Saving or accepting changes failed because more than one entity of type have the same primary key value -


i use repository pattern in asp.net mvc 5, select data table , add 1 entity in data value , want set data in database added entity value saving or accepting changes failed because more 1 entity of type 'blogpost.dal.entity.blogpost.blog' have same primary key value error occured in database row inserted need avoid error.

model = await _iblogserices.bloggetbyid(id); blog data = _db.blog.find(id); _db.blog.remove(data); _db.savechanges(); model.ispublish = true; await _iblogserices.createblog(model); return view(); 

it seem there not problem if bloggetbyid(id) function

public task<blog> bloggetbyid(int id){   return _db.blog.firstordefaultasync(p => p.id ==id); } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -