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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -