Я использую службы домена RIA с Entity Framework 4 и Silverlight 4. Когда я сохраняю изменения, когда возвращается вызов службы, вызываются некоторые функции службы домена, которые устанавливают значение «», которое вообще не должно быть изменено.
у меня две сущности
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, чтобы раскрыть свойство Name в EntityB. Стороне сервера и службе домена никогда не нужно знать об этом свойстве, только для графического интерфейса.
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;
}
}
}
Если я редактирую имя entityA и вызываю 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. Я не доверяю этому решению, поскольку другие изменения могли быть внесены до возврата асинхронного вызова, и эти изменения также были бы отклонены. Идеальным решением было бы игнорировать это значение и вообще НЕ устанавливать его.