Print Page | Close Window

Verifiers affecting Saves incorrectly

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2217
Printed Date: 25-Jul-2026 at 12:41am


Topic: Verifiers affecting Saves incorrectly
Posted By: midnit
Subject: Verifiers affecting Saves incorrectly
Date Posted: 06-Oct-2010 at 12:56pm
Ok, the title isn't quite right...hopefully it doesn't mislead too much.
 
I can reproduce this problem 100% in our application but I cannot explain it at all and I am not going to be able to provide a ton of detail on it, BUT here it is:
 
I have seen this occur on two seperate models. I have not tracked down the simliarities, at first glance there are none.
 
I have an entity (Deal) which had a foreign key property (Location) which if changed it would save the information just fine. When the entity came back from the save it would show Deal.Location as the proper Entity, but Deal.LocationId would be 0. I had seen this awhile back related to an ImportEntities bug...but I am seeing this before doing anything with the entity, this is in the SaveCallback, the args.Entities. So the data saves correctly, the related property shows correctly, but the LocationId (foreign key to Location) was 0. This effects my UI and shows as an emtpy location. After looking everywhere I could think of I randomly commented out my verifiers...and it started working correctly. None of the verifiers have anything do to with Location or LocationId. So I started putting them back in one by one and there was one specifically that would trigger ther problem...so I left it commented out. There are no errors, client or server side (that I have seen). The verifier in question never returned anything but Ok.
 
So now on another model the entity (Confirmation) has a foreign key property (ReceiveMethod) that showed the same symptoms. I went straight to the verifiers, only one on this model, and commented it out and it started working. The verifier has nothing to do with the property. The save works fine, but the entity when returned in args.Entities is showing the Confirmation.ReceiveMethod correctly but the Confirmation.ReceiveMethodId is 0. Before the save the Id's were correct. After removing the verifiers the Id's showed up correctly.
 
Thats all I know. Luckily we were already wanting to eliminate most of our verifiers as they didn't belong in the model so its not a show stopper (for us) but that seems to be a very strange behavior.



Replies:
Posted By: DenisK
Date Posted: 06-Oct-2010 at 3:26pm
Hi midnit;

I'm going to try and repro your issue. I'll have to get back to you. Please let me know if you discover further info on this.


Posted By: midnit
Date Posted: 07-Oct-2010 at 6:03am
I don't have any more info yet but I don't think I made it clear that the Entities that were saving (Deal and Confirmation) have lots of foreign key properties which came back fine. Only the property that had changed (which caused the need to save) was the one that lost its corresponding Id. I did double check that the entity was fine before the save, and it was, it was only the one returned in the save that was missing the [new] Id - it was 0.
 
My application just went to testing so shortly I will have to time to test this further next week.
 
In case its something wrong with our verifier, here is one of them.
 

//public class VerifierProvider : IVerifierProvider

//{

// public IEnumerable<Verifier> GetVerifiers(object verifierProviderContext)

// {

// return new List<Verifier> {

// DisputeOrNoResponseCommentVerifier()

// };

// }

// private static Verifier DisputeOrNoResponseCommentVerifier()

// {

// const string description = "When a confirm is marked Disputed or No Response, the Comment must be updated";

// var verifier = new DelegateVerifier<DealConfirmation>(description, DisputeCommentVerifierCondition);

// verifier.AddTrigger(EntityPropertyNames.ConfComment);

// verifier.AddTrigger(EntityPropertyNames.ConfStatusId);

// verifier.VerifierOptions.ExecutionModes = VerifierExecutionModes.Instance;

// return verifier;

// }

// private static VerifierResult DisputeCommentVerifierCondition(DealConfirmation dealConf, TriggerContext triggerContext, VerifierContext verifierContext)

// {

// if (dealConf.DealConfStatus == DealConfStatusEnum.Disputed || dealConf.DealConfStatus == DealConfStatusEnum.NoResponse)

// {

// return new VerifierResult(dealConf.GetValueRaw("ConfComment", EntityVersion.Original) != dealConf.GetValueRaw("ConfComment", EntityVersion.Current) && !string.IsNullOrEmpty(dealConf.ConfComment));

// }

// return new VerifierResult(true);

// }

//}

If there is anything obviously wrong with the verifier let me know and I'll try changing it.


Posted By: DenisK
Date Posted: 08-Oct-2010 at 12:41pm
midnit;

The verifier seems to look fine. I haven't got a chance to repro yet but as soon as I do, I'll let you know.


Posted By: DenisK
Date Posted: 08-Oct-2010 at 4:53pm
midnit;

I was not able to reproduce. What version are you using?

Here's my test code:

public void StrangeVerificationErrorAffectingForeignKey() {
      var Products = new ObservableCollection<Product>();
      var query = _mgr.Products.Include(p => p.Category);
      query.ExecuteAsync(op => {
        op.Results.ForEach(Products.Add);
        var aProduct = Products[0];
        aProduct.CategoryID = 2;                                 //Change CategoryID from 1 to 2;
        var saveOp = _mgr.SaveChangesAsync();
        saveOp.Completed += saveOp_Completed;
      });
}

void saveOp_Completed(object sender, EntitySavedEventArgs e) {
      foreach(var item in e.Entities) {
        var aProduct = item as Product;
        if(aProduct.CategoryID == 0) { 
           throw new Exception();
        }
     }
}

And I have a DelegateVerifier as follows:

#region IVerifierProvider Members

    public class VerifierProvider : IVerifierProvider {

      public IEnumerable<Verifier> GetVerifiers(object verifierProviderContext) {
        List<Verifier> verifiers = new List<Verifier>();

        verifiers.Add(SomeDelegateVerifier());

        return verifiers;
      }
    }
   
#endregion

#region Verifiers

    private static Verifier SomeDelegateVerifier() {
      var verifier = new DelegateVerifier<Product>("Product verifier", SomeCondition);
      verifier.AddTrigger(EntityPropertyNames.UnitsInStock);
      return verifier;
    }

    private static VerifierResult SomeCondition(Product product, TriggerContext triggerContext,
      VerifierContext verifierContext) {

      return new VerifierResult(VerifierResultCode.Ok);
    }

#endregion



Posted By: midnit
Date Posted: 15-Oct-2010 at 6:04am
I am using 6.0.5. I expect this wont be reproducable until I can find the oddity. I have verifiers that don't cause this...so I'll keep testing when I get the chance and see if I can provide any more light.


Posted By: midnit
Date Posted: 15-Oct-2010 at 6:13am
FYI, I just tried this with 6.0.6 eap and did not have the problem so far.


Posted By: DenisK
Date Posted: 18-Oct-2010 at 2:52pm
Glad to hear that. Please keep us posted if you get into the same problem again with 6.0.6 EAP



Print Page | Close Window