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

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -