Entity Framework - SaveChanges not reflected in database -
savechanges not being reflected in database
i have following code
public async task<int> post([frombody] userentry userentry) { userentry dbuserentry; using (dbcontext db = new dbcontext()) { // update dbuserentry = this.db.userentries .where(u => u.userentryid == userentry.userentryid) .include(u => u.entryplayers.select(y => y.player)) .firstordefault(); dbuserentry.teamname = userentry.teamname; dbuserentry.entryplayers = userentry.entryplayers; //db.entry(dbuserentry).state = entitystate.modified; return db.savechanges(); }
}
i read somewhere need set state modified if uncomment line
//db.entry(dbuserentry).state = entitystate.modified;
i error:-
an entity object cannot referenced multiple instances of ientitychangetracker.
any ideas on how can savechanges work?
use find() method instead of firstordefault()
dbuserentry = this.db.userentries .include(u => u.entryplayers.select(y => y.player)) .find(u => u.userentryid == userentry.userentryid)
Comments
Post a Comment