Validation
Objects that are being saved/persisted into the database must be validated first. The default validation should look like this.
ValidationResult MESSAGES = myNebulaObject.Save();
Inside the Save logic, it says:
public override ValidationResult Save() {
ValidationResult MESSAGES = Validate();
if ( MESSAGES.isError ) {
return MESSAGES;
}
.....
}
Validate is your last chance to guarantee that the object that is being persisted to the database is valid. While you might have logic that tests this, it's a good idea to have validation logic on all of your objects as a final step.
Validate logic can only be added in a partial class. All classed generated by SQLINQ are done with partials. You create in a separate file another class with exactly the same name and override the Validate method. IMPORTANT: You need to do this, because while you could put this logic in the file that gets generated, all that logic you wrote will be lost when you regenerate.
namespace Assets.Data.DataDomain {
public partial class NebulaObject : SpaceObject {
public override ValidationResult Validate() {
ValidationResult myResult = new ValidationResult();
if (this.Density < 0.001f && this.Density > 1.0f) {
myResult.Add(MessageType.Error, "Nebula Densities must be between 0.001 and 1.0.");
}
return myResult;
}
}
}
ValidationResult MESSAGES = myNebulaObject.Save();
Inside the Save logic, it says:
public override ValidationResult Save() {
ValidationResult MESSAGES = Validate();
if ( MESSAGES.isError ) {
return MESSAGES;
}
.....
}
Validate is your last chance to guarantee that the object that is being persisted to the database is valid. While you might have logic that tests this, it's a good idea to have validation logic on all of your objects as a final step.
Validate logic can only be added in a partial class. All classed generated by SQLINQ are done with partials. You create in a separate file another class with exactly the same name and override the Validate method. IMPORTANT: You need to do this, because while you could put this logic in the file that gets generated, all that logic you wrote will be lost when you regenerate.
namespace Assets.Data.DataDomain {
public partial class NebulaObject : SpaceObject {
public override ValidationResult Validate() {
ValidationResult myResult = new ValidationResult();
if (this.Density < 0.001f && this.Density > 1.0f) {
myResult.Add(MessageType.Error, "Nebula Densities must be between 0.001 and 1.0.");
}
return myResult;
}
}
}