0

In an entity called adDetail I have a non-identity field that should never have a duplicate value. adShortURL.

I have a custom New data and a custom edit screen attached to the entity called adDetail.

When the new data screen is used.  The validations on the field works great.  Even going to the database to check for a duplicate value.

However, when I go to edit the same table using existing data, the duplicate value validation stops the screen from saving.

Tried to determine the screen name so put an if around the validation.  Did not find a way.  Tried to set a screen parameter so I could look for it in the validation.  that did not work.  Did not have the screen parameter available in the custom validation method. (might not know where to look).

Please help me figure out how to validate on add and skip the validation on edit screens.

Thanks, Victor

Code Snippet:

partial void AdShortURL_Validate(EntityValidationResultsBuilder results)
{
   // results.AddPropertyError("<Error-Message>");
   // *** There is a Bug here that only happens on the Edit Screen.  On the edit screen, the check happens and finds a duplicate in the databae prohibiting saving.
   //Hit the database and see if there is already a value in there like the one I am Entering.
   IDataServiceQueryable<LSAR_AdDetail> adDetails = 
      this.DataWorkspace.OtLY83U6SQ72SZCG9OtData.LSAR_AdDetails.Where(i =>
         i.AdShortURL == this.AdShortURL);
}
4

1 回答 1

1

I personally wouldn't query it in this way. You are only looking to see if there is one that exists already so I would use an Int variable and return a count of records where AdShortURL == the one you are looking for.

    var myCount = (from items in this.DataWorkspace.OtLY83U6SQ72SZCG9OtData.LSAR_AdDetails
             where items.AdShortURL == this.AdShortURL
             select items).Execute().Count();
于 2012-09-13T13:18:00.507 回答