문제

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