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

Related Questions

I have LINQ statement that looks like this: return ( from c in customers
What I have: LINQ to SQL auto generated class, which corresponds to the shape
I have a LINQ to SQL generated class with a readonly property: <Column(Name:=totalLogins, Storage:=_TotalLogins,
I currently have a LINQ query implemented as a method of my DataContext class.
Ok so, I have a class that's generated when I created the Linq to
I have a LINQ to SQL class (dbml) representing some tables in a database.
I'm have .dbml Linq to SQL class named DExamination.dbml [global::System.Data.Linq.Mapping.TableAttribute(Name=dbo.Examination)] public partial class Examination
I have a Linq to objects statement var confirm = from l in lines.Lines
I have two LINQ objects which have exactly the same columns and I would
I have a linq query and I am trying to put that in to

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.