Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 174979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:37:07+00:00 2026-05-11T13:37:07+00:00

I have a LINQ partial class: public partial class resp { public IEnumerable<RuleViolation> GetRuleViolations()

  • 0

I have a LINQ partial class:

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');     } } 

In my code I would like to be able to check whether a responsibility (dbo.resp) exists before it is deleted.

I am accomplishing this check with a hook to OnValidate as above ... if (action == ChangeAction.Delete) ... and returning an application exception if it fails.

Also, during normal validation, I would like to check to make sure rule violations aren’t made (resp.respName in this case…)

So, normally I can just do a try { } catch { var errors = resps.GetRuleViolations() } and check whether I have validation errors. Of course, that doesn’t know what action is being taken (Changeaction.Delete)

I guess my main question is, how can I have OnValidate return a reason rather than crash my whole app when the Changeaction is delete. Normally I would catch GetRuleViolations but if I put the ‘if statement’ in the GetRuleViolations … it will always be true even during checks to see if the data was correct (in other words, respApprovers.Count() will matter even for checks on new insertions which I don’t want to. I only want those count checks to be made on deletion)

Or possibly more simply stated: I want GetRuleViolations to tell me when someone attempts to delete resp that has respApprovers.Count() > 0 or approvals.Count() > 0 but only when the OnValidate Changeaction is delete.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:37:07+00:00Added an answer on May 11, 2026 at 1:37 pm

    Change GetRuleViolations to accept the ChangeAction parameter and add a parameterless version that calls it with ChangeAction.None (or Update or Insert, as appropriate). Then move your check in there as you want.

    public IEnumerable<RuleViolation> GetRuleViolations( ChangeAction action ) {     if (action == ChangeAction.Delete) {        ...     }     else {        ...     } }  public IEnumerable<RuleViolation> GetRuleViolations() {     return GetRuleViolations( ChangeAction.None ); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 97k
  • Answers 97k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't think you can (see Jon Skeet's comment), but… May 11, 2026 at 7:20 pm
  • Editorial Team
    Editorial Team added an answer Yes - SSL is enough - but SSL is only… May 11, 2026 at 7:20 pm
  • Editorial Team
    Editorial Team added an answer It's only preferable to store references as data members if… May 11, 2026 at 7:20 pm

Related Questions

I have a LINQ to SQL generated class with a readonly property: <Column(Name:=totalLogins, Storage:=_TotalLogins,
im using linq to sql i have a Mission entity, which holds a collection
I have written a function that gets a given number of random records from
Problem 1: I have a simple winforms app and I want to DataBind my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.