سؤال

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