title: Class Structure w/ LINQ, Partial Classes, and Abstract Classes
body: <p>I am following the <a href="http://nerddinnerbook.s3.amazonaws.com/Intro.htm" rel="nofollow noreferrer">Nerd Dinner tutorial</a> as I'm learning ASP.NET MVC, and I am currently on <a href="http://nerddinnerbook.s3.amazonaws.com/Part3.htm" rel="nofollow noreferrer">Step 3: Building the Model</a>.  One part of this section discusses how to integrate validation and business rule logic with the model classes.  All this makes perfect sense.  However, in the case of this source code, the author only validates one class: Dinner.</p>
  
  <p>What I am wondering is, say I have multiple classes that need validation (Dinner, Guest, etc).  It doesn't seem smart to me to repeatedly write these two methods in the partial class:</p>
  
  <pre><code>public bool IsValid
  {
      get { return (GetRuleViolations().Count() == 0); }
  }
  
  partial void OnValidate(ChangeAction action)
  {
      if (!IsValid)
      {
          throw new ApplicationException("Rule violations prevent saving.");
      }
  }
  </code></pre>
  
  <p>What I'm wondering is, can you create an abstract class (because "GetRuleViolations" needs to be implemented separately) and extend a partial class?  I'm thinking something like this (based on his example):</p>
  
  <pre><code>public partial class Dinner : Validation {
      public IEnumerable&lt;RuleViolation&gt; GetRuleViolations() {
          yield break;
      }
  }
  </code></pre>
  
  <p>This doesn't "feel" right, but I wanted to check with SO to get opinions of individuals smarter than me on this.  I also tested it out, and it seems that the partial keyword on the OnValidate method is causing problems (understandably so).  This doesn't seem possible to fix (but I could very well be wrong).</p>
  
  <p>Thanks!</p>