Hi,
I am trying to upgrade my v1.2005 code to the new 2.0 code, but am having a few problems mainly to do with validation.
In v1.2005 I generate a validator class for each entity as follows (based on the original manager classes that were made available). The following code is for my Company Entity
public sealed class CompanyValidator : IEntityValidator
{
private int connectionID=0; // used to pass in the connectionID {default=0}
/// <summary>
/// Constructor
/// </summary>
public CompanyValidator(int connID)
{
connectionID=connID;
}
/// <summary>
/// Entity validation rules for 'Company'
/// </summary>
public bool Validate(object containingEntity)
{
CompanyEntity myEntity = (CompanyEntity)containingEntity;
#region Validation Code
// __LLBLGENPRO_USER_CODE_REGION_START Validation
CompanyEntity myUniqueTest = CompanyManager.FetchUsingUniqueConstraintDisplay( myEntity.Display,connectionID );
if (myUniqueTest!=null && myUniqueTest.CompanyID!=myEntity.CompanyID)
{
throw new ORMEntityValidationException( "The 'Show As' column must be unique. If you are adding a new company, try adding contact details as well as a company name. If you are modifying a company, you can edit the 'Show As' value directly - Save cancelled.",containingEntity);
}
// __LLBLGENPRO_USER_CODE_REGION_END
#endregion
// valid
return true;
}
Then one I have fetched a company from the database into a CompanyEntity, I use the code
myEntity.EntityValidatorToUse = new CompanyValidator(0);
to ensure that the entity uses the validator I want.
Finally, I set all the properties of myEntity and save the entity using
if (myEntity.Validate())
{
CompanyManager.MGRUpdate(myEntity,0);
}
Which validates the code, and throws an exception is there is an error, or saves the record if the validation succeeds.
It all seems very simple to me, however I can see that the validation has changed in v2.0. How do I perform the same functionality using the 2.0 templates (N.B. I am still only generating .NET 1.1 code at thi stage)?
Many thanks in advance