表SysRoles和表SysUsers是多对多关系,CodeFirst模式下已建立好导航,可以添加,删除。现在修改出现问题了,代码如下:
MVCOAEntities db = new MVCOAEntities(); db.Configuration.ValidateOnSaveEnabled = false; //模拟数据从前台发过来 var model = new SysRole { ID = 9, RoleName = "测试修改", SysUsers = new List<SysUser> { new SysUser { ID = 122072 } } }; DbEntityEntry entry = db.Entry<SysRole>(model); entry.State = System.Data.EntityState.Modified; db.SaveChanges();
现在普通属性(如RoleName)是修改成功的,就是导航属性SysUsers改不了,这个问题如何解决呢?谢谢指导!!!
怎么解决的?