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
Post a Comment