EntityFramework附加和更新。需要帮忙

时间:2011-06-12 14:14:30

标签: entity-framework

我正在尝试在下面的代码中更新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();

1 个答案:

答案 0 :(得分:0)

您是否尝试过AttachAsModified