ria 域服务正在回调中设置客户端属性

发布于 2024-11-13 09:03:20 字数 3664 浏览 3 评论 0原文

我正在使用带有实体框架 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 技术交流群。

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

发布评论

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

评论(2

掐死时间 2024-11-20 09:03:20

您可能需要告诉 WCF RIA 有关您的实体的一些属性的更多信息:

public partial class EntityA
{
    [Key]
    public Guid EntityA_Id { get; set; }

    public string Name { get; set; }

    public int EntityB_Id { get; set; }

    [Include]
    [Association("EntityA-EntityB", "EntityA_Id", "EntityB_Id", IsForeignKey=false)]
    public EntityB entityB { get; set; }

}

public partial class EntityB
{
    [Required]
    public string Name { get; set; }

    [Key]
    public int EntityB_Id { get; set; }

    public Guid EntityA_Id { get; set; }

    [Include]
    [Association("EntityA-EntityB", "EntityA_Id", "EntityB_Id", IsForeignKey=true)]
    public EntityCollection<EntityA> entityA { get; set; }
}

You may need to tell WCF RIA a little more about your entities with some attributes:

public partial class EntityA
{
    [Key]
    public Guid EntityA_Id { get; set; }

    public string Name { get; set; }

    public int EntityB_Id { get; set; }

    [Include]
    [Association("EntityA-EntityB", "EntityA_Id", "EntityB_Id", IsForeignKey=false)]
    public EntityB entityB { get; set; }

}

public partial class EntityB
{
    [Required]
    public string Name { get; set; }

    [Key]
    public int EntityB_Id { get; set; }

    public Guid EntityA_Id { get; set; }

    [Include]
    [Association("EntityA-EntityB", "EntityA_Id", "EntityB_Id", IsForeignKey=true)]
    public EntityCollection<EntityA> entityA { get; set; }
}
时光倒影 2024-11-20 09:03:20

这是我的解决方案:

private bool isExpanded = false;

public bool IsExpanded
{
    get { return isExpanded; }
    set
    {
        string stack = (new System.Diagnostics.StackTrace()).ToString();
        if (!stack.Contains("ObjectStateUtility.ApplyState") && isExpanded != value)
        {
            isExpanded = value;
            RaisePropertyChanged("IsExpanded");
        }
    }
}

Here's my solution:

private bool isExpanded = false;

public bool IsExpanded
{
    get { return isExpanded; }
    set
    {
        string stack = (new System.Diagnostics.StackTrace()).ToString();
        if (!stack.Contains("ObjectStateUtility.ApplyState") && isExpanded != value)
        {
            isExpanded = value;
            RaisePropertyChanged("IsExpanded");
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文