Reputation: 4866
I try to right a method which result is boolean for custom validation in a model!
[CustomValidation(typeof(SpecialValidator), "IsUniQueCountryCode")]
It must be sync so the method can have a result value:
public static ValidationResult IsUniQueCountryCode(string value) {
if (value.Length > 0)
{
DSCountry _context = new DSCountry();
ObservableCollection<MCountry> List = new ObservableCollection<MCountry>();
LoadOperation<Country> loadOp = _context.Load((_context.GetCountryByCodeQuery(value)).Where(s => s.ISOCode == value));
IEnumerable<Country> Entities;
bool test = false;
loadOp.Completed += (s, e) =>
{
test = true;
};
//
if (test == true)
{
}
//
}
return ValidationResult.Success;
}
How can I make the load synchronous?
Upvotes: 1
Views: 297
Reputation: 70327
Silverlight doesn't support synchronous service calls. So unless you want to use really ugly hacks (see link below), you need to pre-load that information when the application starts or find a way to rewrite it in an asynchronous fashion.
http://www.codeproject.com/KB/silverlight/SynchronousSilverlight.aspx
Oh, and validation routines should be really, really fast. They may be called at any time, often for no apparent reason, so making a service call inside them is a bad idea.
Upvotes: 2