使用 .NET RIA 数据服务删除 Silverlight 3 中的数据
我们正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误系统有点挑剔。尝试一下这个,如果有错误的话,就会得到错误,这会给你一个想法。我的问题是对其他表的依赖关系,需要先删除对象,然后才能删除对象。例如:删除工单之前删除的任务。
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.
在上面的代码片段中,我建议使用回调参数而不是事件处理程序。
回调模型是为 Load/SubmitChanges 的调用者设计的,而事件是为获取 LoadOperation/SubmitOperation 引用的其他代码设计的。
希望有帮助...
In the code snippet above, I'd suggest using the callback parameter rather than an event handler.
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...