title: Dynamic Or Clause Linq
body: <p>Today we currently have a statement like this:</p>
  
  <pre><code>var Query = (from dp in db.Patients
              select dp);
  
  var UserID = User.Identity.GetUserId();
  
  if (User.IsInRole("Administrator"))
  {
      Query = Query.Where(x =&gt; x.AdministratorID == UserID);
  }
  if (User.IsInRole("Counselor"))
  {
      Query = Query.Where(x =&gt; x.CounselorID == UserID);
  }
  if (User.IsInRole("Physician"))
  {
      Query = Query.Where(x =&gt; x.PhysicianID == UserID);
  }
  </code></pre>
  
  <p>The problem is we have Users that can have multiple roles. If a User is both an Counselor and Physician we want the system to pull back all patients where CounselorID == UserID or PhysicianID == UserID.</p>
  
  <p><strong>How can this be accomplished dynamically if we don't know what role a user will have when the page is loaded?</strong></p>
  
  <p>The current .Where clause just uses an <strong>AND</strong> statement we need an <strong>OR</strong> statment.</p>
  
  <p>Ideally there would be a solution like this:</p>
  
  <pre><code>if (User.IsInRole("Administrator"))
  {
       Query = Query.Where(x =&gt; x.AdministratorID == UserID);
  }
  if (User.IsInRole("Counselor"))
  {
       Query = Query.WhereOr(x =&gt; x.CounselorID == UserID);
  }
  if (User.IsInRole("Physician"))
  {
       Query = Query.WhereOr(x =&gt; x.PhysicianID == UserID);
  }
  </code></pre>