Entity Framework model updates, but model's list of other items not updating -


here's issue. revived old text based game of mine used flat files saving , loading. have been porting old c++ code c# using mvc 4 entity framework 5 , sql server 2012. rendering pages razor views straightforward. problem comes when building wizard creating/editing rooms.

a room contains collection of exit objects. works fine when first create room , assign exits. not work when edit room , change exits. putting breakpoint in edit code shows exit value has changed, no problem setting room state modified, , room appears save fine i.e. changes name , description updated. however, exit info not.

i tried loop through list of exits, mark each exit modified, throws sorts of errors during save. question this. correct way update list of exits on room model?

i've tried other solutions here, refresh, copying new values old values before saving, nothing works. how exit objects update database. in advance.

public abstract class entity {     public virtual int id { get; set; }      public virtual string name { get; set; }     public virtual string description { get; set; }  }  public class room : entity {     public virtual icollection<exit> exits { get; set; } }  public class exit : entity {     // room belong     public int roomid { get; set; }     public room room { get; set; }      // room connect     public int? toroomid { get; set; }     public room toroom { get; set; } } 

my repository methods

public ienumerable<room> allroomsinclusive() {     var rooms = context.rooms.include(r => r.exits).tolist();     return rooms; }  public void update(room room) {     context.entry(room).state = entitystate.modified; }  public void save() {     context.savechanges(); } 

i see toroomid updated in controller's edit method i.e. toroomid 6 during method , edit during post method set toroomid 10. value not reflected in database on save.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -