EF4 STE 和 MVC2 - ChangeTracker 未发布

发布于 2024-09-13 09:59:47 字数 861 浏览 8 评论 0原文

我正在尝试使用实体框架自我跟踪实体设置 MVC2 应用程序。我的视图是由 STE T4 模板生成的实体类型的强类型视图。这是我的 GET:

    public ActionResult Edit(int id)
    {
        var ri = new App1Service.App1Client().GetMyObj(id);
        var changeTracking = ri.ChangeTracker.ChangeTrackingEnabled;  // this shows true
        return View(ri);
    }

到目前为止,一切顺利。然而,当此表单 POST 时,ChangeTracker 为 null/重置为默认值,因此,STE 似乎突然忘记了它应该跟踪自身:

    [HttpPost]
    public ActionResult Edit(MyObj ri)  
    {
         // MyObj.ChangeTracker.ChangeTrackingEnabled now shows false
         // so the following line doesn't save anything:
         new App1Service.App1Client().SaveMyObj(ri);
         return RedirectToAction("Index");
    }

What's the Secret to getting the Strong-typed-view tohang on (and POST回来)整个STE?如果我必须再进行一次读取以获得原始值然后应用更改,这似乎违背了自我跟踪实体的目的,不是吗?

I'm trying to set up an MVC2 app with Entity Framework Self-Tracking-Entities. My view is a strongly-typed view of the entity type generated by the STE T4 template. Here's my GET:

    public ActionResult Edit(int id)
    {
        var ri = new App1Service.App1Client().GetMyObj(id);
        var changeTracking = ri.ChangeTracker.ChangeTrackingEnabled;  // this shows true
        return View(ri);
    }

So far, so good. When this form POSTs, however, ChangeTracker is null / reset to default values, and thus, the STE seems suddenly to forget that it's supposed to be tracking itself:

    [HttpPost]
    public ActionResult Edit(MyObj ri)  
    {
         // MyObj.ChangeTracker.ChangeTrackingEnabled now shows false
         // so the following line doesn't save anything:
         new App1Service.App1Client().SaveMyObj(ri);
         return RedirectToAction("Index");
    }

What's the secret to getting the strongly-typed-view to hang onto (and POST back) the whole STE? If I have to go and do another read to get original values and then apply changes, that seems to defeat the purpose of self-tracking-entities, doesn't it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文