ria 域服务正在回调中设置客户端属性
我正在使用带有实体框架 4 和 silverlight 4 的 RIA 域服务。当我保存更改时,当服务调用返回时,会调用一些域服务函数,将值设置为“”,根本不应该更改。
我有两个实体
service.metadata.cs:
public partial class EntityA
{
[Key]
public Guid EntityA_Id { get; set; }
public string Name { get; set; }
public int EntityB_Id { get; set; }
[Include]
public EntityB entityB { get; set; }
}
public partial class EntityB
{
[Required]
public string Name { get; set; }
public int EntityB_Id { get; set; }
public EntityCollection<EntityA> entityA { get; set; }
}
在客户端,我在 EntityA 上有一个 Extra 属性来公开 EntityB 的 Name 属性。服务器端和域服务永远不需要知道这个属性,它仅适用于 GUI。
public partial class EntityA
{
//Tags I have tried:
//[IgnoreDataMember]
//[XmlIgnore]
//[Ignore]
//[Exclude]
public string NameOf_EntityB
{
get
{
return this.entityB == null ? string.Empty : this.entityB.Name;
}
set
{
this.entityB.Name = value;
}
}
}
如果我编辑实体 A 的名称并调用 serviceContext.SubmitChanges(),当调用返回某些域服务进程时,将设置 EntityA.NameOf_EntityB = ""; 因此,从用户的角度来看,他们保存一个值,而另一个值则为空。
我需要阻止这种情况发生。我尝试过各种数据属性,但它们要么在客户端不起作用,要么没有效果。
知道如何阻止域服务更改此值吗?
这是值更改之前的调用堆栈:
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.ObjectStateUtility.**ApplyValue**(object o, object value, System.Reflection.PropertyInfo propertyInfo, System.Collections.Generic.IDictionary<string,object> originalState, System.ServiceModel.DomainServices.Client.LoadBehavior loadBehavior) + 0x74 bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.ObjectStateUtility.ApplyState(object o, System.Collections.Generic.IDictionary<string,object> stateToApply, System.Collections.Generic.IDictionary<string,object> originalState, System.ServiceModel.DomainServices.Client.LoadBehavior loadBehavior) + 0x330 bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.Entity.ApplyState(System.Collections.Generic.IDictionary<string,object> entityStateToApply, System.ServiceModel.DomainServices.Client.LoadBehavior loadBehavior) + 0x68 bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.Entity.Merge(System.ServiceModel.DomainServices.Client.Entity otherEntity, System.ServiceModel.DomainServices.Client.LoadBehavior loadBehavior) + 0x5a bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.DomainContext.ApplyMemberSynchronizations(System.Collections.Generic.IEnumerable<System.ServiceModel.DomainServices.Client.ChangeSetEntry> changeSetResults) + 0x10e bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.DomainContext.ProcessSubmitResults(System.ServiceModel.DomainServices.Client.EntityChangeSet changeSet, System.Collections.Generic.IEnumerable<System.ServiceModel.DomainServices.Client.ChangeSetEntry> changeSetResults) + 0x262 bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.DomainContext.CompleteSubmitChanges(System.IAsyncResult asyncResult) + 0x1cb bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.DomainContext.SubmitChanges.AnonymousMethod__5() + 0x2e bytes
编辑: 暂时找到了解决办法。在 ServiceContext.submitChanges() 调用的回调中,我可以调用 ServiceContext.RejectChanges() 来撤消对 EntityB 所做的更改。我不相信这个解决方案,因为在异步调用返回之前可能已经进行了其他更改,并且这些更改也将被拒绝。理想的解决方案是忽略该值并且根本不设置
I'm using RIA domain services, with entity framework 4 and silverlight 4. When I save changes, when the service call returns, some domain service functions are called wich sets a value to "" that should not be changed at all.
I have two entities
service.metadata.cs:
public partial class EntityA
{
[Key]
public Guid EntityA_Id { get; set; }
public string Name { get; set; }
public int EntityB_Id { get; set; }
[Include]
public EntityB entityB { get; set; }
}
public partial class EntityB
{
[Required]
public string Name { get; set; }
public int EntityB_Id { get; set; }
public EntityCollection<EntityA> entityA { get; set; }
}
On the client side I have a Extra property on EntityA to expose the Name property od EntityB. The server side and domain service never need to know about this property, its for GUI only.
public partial class EntityA
{
//Tags I have tried:
//[IgnoreDataMember]
//[XmlIgnore]
//[Ignore]
//[Exclude]
public string NameOf_EntityB
{
get
{
return this.entityB == null ? string.Empty : this.entityB.Name;
}
set
{
this.entityB.Name = value;
}
}
}
If I edit the entityA's name and call serviceContext.SubmitChanges(), when the call returns some domain service process is setting the EntityA.NameOf_EntityB = ""; So from a user point of view, they save one value and the other blanks out.
I need to stop this from happening. I have tried various data attributes, but they either don't work on the client side, or have no effect.
Any idea what to do to stop the domain service from changing this value?
here's the callstack right before the value is changed:
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.ObjectStateUtility.**ApplyValue**(object o, object value, System.Reflection.PropertyInfo propertyInfo, System.Collections.Generic.IDictionary<string,object> originalState, System.ServiceModel.DomainServices.Client.LoadBehavior loadBehavior) + 0x74 bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.ObjectStateUtility.ApplyState(object o, System.Collections.Generic.IDictionary<string,object> stateToApply, System.Collections.Generic.IDictionary<string,object> originalState, System.ServiceModel.DomainServices.Client.LoadBehavior loadBehavior) + 0x330 bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.Entity.ApplyState(System.Collections.Generic.IDictionary<string,object> entityStateToApply, System.ServiceModel.DomainServices.Client.LoadBehavior loadBehavior) + 0x68 bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.Entity.Merge(System.ServiceModel.DomainServices.Client.Entity otherEntity, System.ServiceModel.DomainServices.Client.LoadBehavior loadBehavior) + 0x5a bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.DomainContext.ApplyMemberSynchronizations(System.Collections.Generic.IEnumerable<System.ServiceModel.DomainServices.Client.ChangeSetEntry> changeSetResults) + 0x10e bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.DomainContext.ProcessSubmitResults(System.ServiceModel.DomainServices.Client.EntityChangeSet changeSet, System.Collections.Generic.IEnumerable<System.ServiceModel.DomainServices.Client.ChangeSetEntry> changeSetResults) + 0x262 bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.DomainContext.CompleteSubmitChanges(System.IAsyncResult asyncResult) + 0x1cb bytes
System.ServiceModel.DomainServices.Client!System.ServiceModel.DomainServices.Client.DomainContext.SubmitChanges.AnonymousMethod__5() + 0x2e bytes
Edit:
found a work around for now. In the callback of the ServiceContext.submitChanges() call I can call ServiceContext.RejectChanges() to undo the change that was made to EntityB. I don't trust this solution though as other changes could have been made before the async call returns and those changes would be rejected as well. The ideal solution would be to have that value ignored and NOT set at all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要告诉 WCF RIA 有关您的实体的一些属性的更多信息:
You may need to tell WCF RIA a little more about your entities with some attributes:
这是我的解决方案:
Here's my solution: