title: ASP.NET EntityDataSource WHERE Clause
body: <p>I am new to ASP.NET and could use some help writing a where clause for my EntityDataSource.</p>
  
  <p>I have the following EDS:</p>
  
  <pre><code>&lt;asp:EntityDataSource ID="RidesEDS" runat="server" 
      ContextTypeName="RamRideOps.RamRideOpsEntities" EnableFlattening="False" 
      EntitySetName="Rides" EnableDelete="True" EnableUpdate="True"&gt;
  &lt;/asp:EntityDataSource&gt;
  </code></pre>
  
  <p>There is a database of 'Rides' and a database of 'AdminOptions' which contains two dates: validDate1 and validDate2... I need the EDS to only show rides that have 'CallTime's between the two valid dates. To facilitate this, on page_load I am populating two hidden fields with the valid dates (hf_validDate1 and hf_validDate2). Can anyone show me what I need to add to the EntityDataSource code to accomplish this by comparing CallTimes to the values of the hf's with a WHERE clause?</p>
  
  <p>EDIT:</p>
  
  <p>Here is what I have so far, not quite working though..</p>
  
  <pre><code>&lt;asp:EntityDataSource ID="RidesEDS" runat="server" 
          ContextTypeName="RamRideOps.RamRideOpsEntities" EnableFlattening="False" 
          EntitySetName="Rides" EnableDelete="True" EnableUpdate="True" Where="it.TimeOfCall &gt; @validDate1Param AND it.TimeOfCall &lt; @validDate2Param"&gt;
  
          &lt;WhereParameters&gt;
          &lt;asp:ControlParameter ControlID="hf_validDate1" DbType="DateTime" 
            DefaultValue="1/01/2012 12:00:00 PM" Name="validDate1Param" PropertyName="Value" /&gt;
            &lt;asp:ControlParameter ControlID="hf_validDate2" DbType="DateTime" 
            DefaultValue="1/01/2112 12:00:00 PM" Name="validDate2Param" PropertyName="Value" /&gt;
          &lt;/WhereParameters&gt;
      &lt;/asp:EntityDataSource&gt;
  
  &lt;asp:HiddenField ID="hf_validDate1" runat="server" /&gt;
  &lt;asp:HiddenField ID="hf_validDate2" runat="server" /&gt;
  </code></pre>
  
  <p>Code-Behind:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
              using(RamRideOpsEntities myEntities = new RamRideOpsEntities())
              {
                  var validDates = (from a in myEntities.AdminOptions
                                    select new { a.ValidDate1, a.ValidDate2 }).FirstOrDefault();
  
                  if(validDates != null)
                  {
                      hf_validDate1.Value = validDates.ValidDate1.ToString();
                      hf_validDate1.Value = validDates.ValidDate2.ToString();
                  }
              }            
          }
  </code></pre>