提交时可以编辑 WCF Ria 服务实体吗?
我有一个使用 WCF RIA 服务的 silverlight 应用程序。
我想在每次属性更改时提交更改。
但是,如果用户在提交完成之前尝试更改同一实体中的另一个属性,则会收到以下错误:
“此实体当前是只读的。存在以下条件之一:已调用自定义方法,正在进行提交操作,或者实体类型不支持编辑操作”
场景:
- 用户更改实体 1 中的属性 A
- 提交 WCF DataContext
- 应用程序捕获更改并在用户更改后立即 实体 1 中的属性 B。然而,这由于正在提交,该属性是只读的。
是否可以更改 DataContext 的行为,以便我可以在提交过程中更新实体?
I have a silverlight application that uses WCF RIA services.
I want to submit changes every time a property is changed.
However if a user tries to change a another property in the same entity before the submit is complete I get the following error:
"This entity is currently read-only. One of the following conditions exist: a custom method has been invoked, a submit operation is in progress, or edit operations are not supported for the entity Type"
Scenario:
- User changes property A in Entity 1
- Application catches change and submits WCF DataContext
- Soon after user changes property B in Entity 1. However this property is read-only due to submit in progress.
Is it possible change the behaviour of the DataContext so that I can update an entity during the submit process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意 - 我可能不太同意这个回答:
让我试着理解你的意思:
如果我是正确的,在界面上,绑定到某个实体的值正在更改。这个实体,就是你想要在服务器上实时更新的实体。如果是这种情况,我会推荐这个:
假设我有一个文本框,当用户在文本框中键入值时,它会更新绑定实体,并且我希望该实体同时在服务器上更新 - 定义一个行为来采用 keyup 方法并触发例如 (
AssociatedObject.GetBindingExpression(TextBox.TextProperty).UpdateSource();
)另外,在这种行为中,我会让文本框能够定义一个绑定到 OnKeyUp 事件的方法,这样我就可以说,一旦用户按下“Enter”键,然后实际上在服务器上进行更新。此外,我会创建一个加载屏幕/子窗口来表示“保存” - 然后会导致“阻止”发生,以防止在保存期间进行任何进一步的用户干预。回电时。我会关闭显示正在加载的窗口。
现在,就像我说的,我不确定这是否是您正在寻找的答案,但这个想法背后的理论,特别是仅在输入或最终更改时阻止似乎是您最好的选择。文本框的行为示例如下:
包含您的库:
using CustomControlsUI.Extensions;
定义文本框的类:
public class TTextBoxKeyUpBehavior:Behavior
为要动态绑定的 ontextkeyup 定义方法指针: protected MethodInfo OnTextBoxKeyUp { get;放; }
定义命名要绑定到的 OnTextKeyUpMethod 的公共字符串:
OnTextBoxKeyUpMethod
在行为中定义 TextboxKeyUp 事件:
覆盖 On Attached 和 On Detached 方法:
用法:
包含存储行为的命名空间:
xmlns:ccui="clr-namespace:CustomControlsUI.Behaviors; assembly=CustomControlsUI"
包含 System.Windows.Interactivity 和 Microsoft.Expression.Interactions 的命名空间:
附加OnKeyUpTo 视图模型中所需的方法:
在视图模型中实现应实现 System.ComponentModel 中的 INotifyPropertyChanged 的方法和属性
最后定义 key up 方法以通知服务器更改:
请注意:我可能会对这个答案感到厌烦。但这只是基于我认为你正在寻找的东西......
PLEASE NOTE - I MIGHT BE WAYYYY OFF ON THIS RESPONSE:
Let me try to get what your saying:
If i'm correct, on the interface, values are being changed which are bound to some entity. This entity, is what you want to be updated in real time on the server. If this is the case, I would recommend this:
Let's say I have a text box, and as the user types the value in the text box, it updates the binding entity, and i want that entity to be updated on the server at the same time - define a behaviour to take the keyup method and trigger e.g. (
AssociatedObject.GetBindingExpression(TextBox.TextProperty).UpdateSource();
)Also, in this behaviour, I would give the text box the ability to define a method to bind to for the OnKeyUp event allowing me, to say, once the user presses "Enter" then actually do the udpate on the server. In addition, i would create a loading screen/child window to say "saving" - that would then cause "blocking" to occur to prevent any further user intervention during the save. On the call back. I would close the window that said loading.
Now, like i said, i'm not sure if this is the answer your are looking for, but the theory behind the idea, especially the blocking only on enter or on a final change seems to be your best bet. An example of the behaviour for the text box is below:
Include your library:
using CustomControlsUI.Extensions;
Define the class for the text box:
public class TTextBoxKeyUpBehavior:Behavior<TextBox>
Define the method pointer for the ontextkeyup that you want to dynamically bind to:
protected MethodInfo OnTextBoxKeyUp { get; set; }
Define the public string that names the OnTextKeyUpMethod to bind to:
OnTextBoxKeyUpMethod
Define the TextboxKeyUp event in the behavior:
Override the On Attached and On Detached methods:
Usage:
Include the namespace where the behavior is stored:
xmlns:ccui="clr-namespace:CustomControlsUI.Behaviors;assembly=CustomControlsUI"
Include the namespaces for System.Windows.Interactivity and Microsoft.Expression.Interactions:
Attach the OnKeyUpTo the desired method in the viewmodel:
Implement the method and property in the view model that should implement INotifyPropertyChanged found in System.ComponentModel
Finally define the key up method to notify the server of the change:
Please Note: I could be WAYYYYYYYYYYY Off on this answer. But it's just based on what i think you're looking for....