我正在尝试在下面的代码中更新indexorder。没有错误,但数据库中的值未更新。尝试了不同的方法但没有成功。
readonly WMEntities _db = new WMEntities();
var subMenu = new SubMenu { Id = id };
subMenu.EntityKey = new EntityKey("WMEntities.SubMenus", "Id", id);
_db.Attach(subMenu);
subMenu.IndexOrder = index;
_db.SaveChanges();
----------------------------------------------------------------
SubMenu subMenu = new SubMenu();
subMenu.Id = id;
subMenu.IndexOrder = index;
_db.AttachTo("WMEntities.SubMenus", subMenu);
_db.SaveChanges();