使用 .NET RIA 数据服务删除 Silverlight 3 中的数据

发布于 2024-08-02 04:28:44 字数 394 浏览 0 评论 0原文

我们正在尝试使用 RIA 服务。我似乎不知道如何删除记录。这是我尝试使用的代码。

   SomeDomainContext _SomeDomainContext = (SomeDomainContext)(productDataSource.DomainContext);
    Product luckyProduct = (Product)(TheDataGrid.SelectedItem);

    _SomeDomainContext.Products.Remove(luckyProduct);

    productDataSource.SubmitChanges();

从实体部分删除对象工作正常,但它似乎对数据库没有任何作用。我是否按照预期使用了这些对象,或者是否有不同的保存方式?

We're trying to play around with RIA Services. I can't seem to figure out how to delete a record. Here's the code I'm trying to use.

   SomeDomainContext _SomeDomainContext = (SomeDomainContext)(productDataSource.DomainContext);
    Product luckyProduct = (Product)(TheDataGrid.SelectedItem);

    _SomeDomainContext.Products.Remove(luckyProduct);

    productDataSource.SubmitChanges();

The removing the object from the Entity part works fine, but it doesn't seem to do anything to the DB. Am I using the objects like I'm supposed to, or is there a different way of saving things?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聊慰 2024-08-09 04:28:44

错误系统有点挑剔。尝试一下这个,如果有错误的话,就会得到错误,这会给你一个想法。我的问题是对其他表的依赖关系,需要先删除对象,然后才能删除对象。例如:删除工单之前删除的任务。

System.Windows.Ria.Data.SubmitOperation op = productDataSource.SubmitChanges();
op.Completed += new EventHandler(op_Completed);

void TicketsLoaded_Completed(object sender, EventArgs e) {
   System.Windows.Ria.Data.SubmitOperation op = (System.Windows.Ria.Data.SubmitOperation)sender;
   if (op.Error != null) {
      ErrorWindow view = new ErrorWindow(op.Error);
      view.Show();
   }
}

The error system is a little finicky. Try this o get the error if there is one and that will give you an idea. My problem was dependencies to other tables needing deletion first before the object could be. Ex: Tasks deleted before deleting the Ticket.

System.Windows.Ria.Data.SubmitOperation op = productDataSource.SubmitChanges();
op.Completed += new EventHandler(op_Completed);

void TicketsLoaded_Completed(object sender, EventArgs e) {
   System.Windows.Ria.Data.SubmitOperation op = (System.Windows.Ria.Data.SubmitOperation)sender;
   if (op.Error != null) {
      ErrorWindow view = new ErrorWindow(op.Error);
      view.Show();
   }
}
握住我的手 2024-08-09 04:28:44

在上面的代码片段中,我建议使用回调参数而不是事件处理程序。

productsDataSource.SubmitChanges(delegate(SubmitOperation operation) {
    if (operation.HasError) {
        MessageBox.Show(operation.Error.Message);
    }
}, null);

回调模型是为 Load/SubmitChanges 的调用者设计的,而事件是为获取 LoadOperation/SubmitOperation 引用的其他代码设计的。

希望有帮助...

In the code snippet above, I'd suggest using the callback parameter rather than an event handler.

productsDataSource.SubmitChanges(delegate(SubmitOperation operation) {
    if (operation.HasError) {
        MessageBox.Show(operation.Error.Message);
    }
}, null);

The callback model is designed for the caller of Load/SubmitChanges, while the event is designed for other code that gets a reference to a LoadOperation/SubmitOperation.

Hope that helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文