阅读背景:

LINQ to SQL分部类OnValidate Changeaction.Delete

来源:互联网 

I have a LINQ partial class:

我有一个LINQ分部类:

public partial class resp
{
    public IEnumerable<RuleViolation> GetRuleViolations()
    {
        if (String.IsNullOrEmpty(respName))
            yield return new RuleViolation("Responsibility name required", "respName");
        yield break;
    }

    public bool IsValid
    {
        // Quick method for checking to see whether an object contains any RuleViolations
        get { return (GetRuleViolations().Count() == 0); }
    }

    partial void OnValidate(ChangeAction action)
    {
        // Hook to LINQ to be notified before db is actually persisted .. and check to make sure resp is not used by respApprover or approvals
        if (action == ChangeAction.Delete && ((respApprovers.Count() != 0 || approvals.Count() != 0)))
            throw new ApplicationException("You cannot delete a responsibility that is in use");
        if (!IsValid)
            throw new ApplicationException("Rule violations prevent saving");
    }
}
p



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: