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);
}