Вопрос

I am using XAF, I have a Questions Business object and Answers Business object.There are one to many relationship between these business objects.Every question must have one correct answer.If there are more than one correct answer or no correct answer,I should cancel saving.How can I satisfy this condition?

Это было полезно?

Решение

You can use the built-in XAF Validation module and the RuleCriteria attribute. If your business rule cannot be expressed via the Criteria Language syntax, then you can use the RuleFromBooleanProperty attribute and write any logic you want in code.

Другие советы

public partial class Question:XPObject
{
    protected override void OnSaving()
    {
        if(this.Answers.Count == 1) base.OnSaving();
        else throw new UserFriendlyException( "You need to have one correct answer." );
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top