c# - Trying to update the list of an entity -


so setup following: supportticket - contains list of supportticketmessags called messages. supportticketmessage - contains userprofile , message

i'm trying add supportticketmessage list of existing supportticket following method:

public void addreply(string message, userprofile author) {     using (contextdb db = new contextdb())     {         supportticketmessage msg = new supportticketmessage(author, message);         messages.add(msg);         db.userprofiles.attach(owner);         db.entry(this).state = entitystate.modified;         db.savechanges();     } } 

however whenever attempt following error:

an object same key exists in objectstatemanager. objectstatemanager cannot track multiple objects same key.

at following line:

db.entry(this).state = entitystate.modified; 

to sum up: i'm adding object list , object saved database. how can this?

you don't have explicitly change state of object. entity framework automatically.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -