Grid Filter and the EntityDataSource Control WhereParameters

9 posts, 1 answers
  1. Gernot
    Gernot avatar
    32 posts
    Member since:
    May 2008

    Posted 11 Aug 2009 Link to this post

    Does the grid-filter not work with EntityDataSource-Control when AutoGenerateWhereClause is set to "true" ?

    I've a grid bound on entitydatasource-control.
    The DataSourceControl has whereparameters and the property AutoGenerateWhereClause is set to "true"
    I'm filtering the column "CreateDate" with a selected value of radDatePicker on my page.
    The first call of the page works fine and the data is filtered.

    If i try to filter a column wiht "Equal" then an System.InvalidOperationException accours with the message:
    AutoGenerateWhereClause can't be 'true' when Where is defined.


    Here is the aspx-code:

          <asp:EntityDataSource ID="InventoryEntityDataSource" runat="server"  
                    ConnectionString="name=Entities" DefaultContainerName="Entities"  
                    EnableDelete="True" EnableInsert="True" EnableUpdate="True"  
                    EntitySetName="Inventory"  
                EntityTypeFilter="Inventory" AutoGenerateWhereClause="True"  
                Select="" Where=""
                    <WhereParameters> 
                        <asp:ControlParameter ControlID="ProcessDateRadDatePicker" Name="CreateDate"  
                            PropertyName="SelectedDate" /> 
                    </WhereParameters> 
                </asp:EntityDataSource> 




    Thank you for your help!



  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 12 Aug 2009 Link to this post

    Hello Alaeddin Gedik,

    Since there is no EntityDataSourceView similar other MS data source controls the grid will try to use Where of the EntityDataSource and that is why you get this error.

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Gernot
    Gernot avatar
    32 posts
    Member since:
    May 2008

    Posted 13 Aug 2009 Link to this post

    Is it posibble to bind a Control value as Default-Filter ???
    I need "CreateDate" Control as Default Filter and also need the posibilitty to filter by column in the Grid.
    How can i achieve this with EntityDataSource Control bound to the grid?
  4. Gernot
    Gernot avatar
    32 posts
    Member since:
    May 2008

    Posted 15 Aug 2009 Link to this post

    What i need is really simple but i cant get it to work.

    I want to bind my grid to a entitydatasource control with a default where parameter for the column CreateDate, wich is bound to a raddatepicker.
    I also need the posibility to filter by column in the grid with the filter-bar.

    Is there any solution for this?
  5. Answer
    Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 18 Aug 2009 Link to this post

    Hi Alaeddin,

    In order to achieve the desired scenario you may construct the where clause inside DataSource's selecting event. I have attached a test page which demonstrates a simple implementation of such approach.

    Best wishes,
    Rosen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Gernot
    Gernot avatar
    32 posts
    Member since:
    May 2008

    Posted 20 Aug 2009 Link to this post

    Thank You :-)
    I found another solution.

    1. Use Object-Datasource with returntyp IQueryable
    2. Funnction-Parameter: SelectDate
    3. Write your linq to entities query

  7. Peter
    Peter avatar
    98 posts
    Member since:
    Mar 2012

    Posted 01 Mar 2015 in reply to Gernot Link to this post

    Thanks Rosen - this is what I needed.

    (I reversed the combined WHERE clause for me - not sure if the SQL Execution Plan is smart enough to pick the index first or it needs it in the correct order - least specific to most specific). 
  8. Roger
    Roger avatar
    26 posts
    Member since:
    Aug 2012

    Posted 31 Jul 2017 Link to this post

    For me the easiest approach which always works (also in combination with column filters) is to use the OnQueryCreated event of EntityDataSource control.

    Sample:

    protected void InventoryEntityDataSource_QueryCreated(object sender, QueryCreatedEventArgs e)
    {
        var query = e.Query as IQueryable<Inventory>;
     
        if (RadCalendar1.SelectedDate > DateTime.MinValue)
        {
            query = query.Where(p => p.OrderDate == RadCalendar1.SelectedDate);
        }
        else
        {
            //TODO: Adapt query with default value
             
        }
     
        e.Query = query;
    }
  9. Eyup
    Admin
    Eyup avatar
    3988 posts

    Posted 02 Aug 2017 Link to this post

    Hello Roger,

    Thank you for sharing your specific approach with our community. I may prove helpful to other developers as well.

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top