locked
entitydatasource filtering for items last month RRS feed

  • Question

  • User736629826 posted

    Hi,

    I have a EntityDataSource linked to a database table (SQL Server). I want to add a where statement in which I select only records for the last month. In the table I have a field named LogDate (a DateTime field).

    How can I add a proper where statement for this specification?

    Paul

    Monday, November 5, 2012 5:05 AM

All replies

  • User3866881 posted

    I want to add a where statement in which I select only records for the last month. In the table I have a field named LogDate (a DateTime field).

    Hi,

    You can just do that in the Wizard of EntityFrameworkDataSource, and then choose the ControlParameter to a TextBox or a Dropdownlist and do binding with that.

    For more you can look at the simiar sample and torturial (step by step) here:

    http://blogs.msdn.com/b/adonet/archive/2008/06/18/tutorial-entity-data-source-control.aspx

    Monday, November 5, 2012 8:22 PM
  • User736629826 posted

    Hi,

    I have added a controlparameter to the EntityDataSource:

    <asp:EntityDataSource ID="EntityDataSourceChangeLog" runat="server" 
    ConnectionString='name=FlightmapDBEntities' DefaultContainerName="FlightmapDBEntities" EntitySetName="ChangeLog" OrderBy="it.[LogDate] desc" Where="it.LogDate &gt; @showfromdate" EnableFlattening="False"> <WhereParameters> <asp:ControlParameter ControlID="RadDatePicker1"
    Name="showfromdate" PropertyName="SelectedDate" Type="DateTime" /> </WhereParameters> </asp:EntityDataSource> <telerik:RadDatePicker ID="RadDatePicker1" runat="server" Visible="true"></telerik:RadDatePicker>

    With this I get an error:
    WhereParameters cannot be specified unless AutoGenerateWhere==true or Where is specified.

    When I add AutoGenerateWhereClause="True" as mentioned in the errormessage I get another error:
    A property with name 'showfromdate' does not exist in metadata for entity type 'Bicore.Flightmap.DAL.ChangeLog'.

    What am I doing wrong?

    Paul

    Tuesday, November 6, 2012 3:52 AM