This is a migrated thread and some comments may be shown as answers.

Grid Filter and the EntityDataSource Control WhereParameters

8 Answers 417 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gernot
Top achievements
Rank 1
Gernot asked on 11 Aug 2009, 12:11 PM
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!



8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Aug 2009, 02:07 PM
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.
0
Gernot
Top achievements
Rank 1
answered on 13 Aug 2009, 08:55 AM
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?
0
Gernot
Top achievements
Rank 1
answered on 15 Aug 2009, 12:56 PM
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?
0
Accepted
Rosen
Telerik team
answered on 18 Aug 2009, 01:58 PM
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.
0
Gernot
Top achievements
Rank 1
answered on 20 Aug 2009, 08:24 AM
Thank You :-)
I found another solution.

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

0
Peter
Top achievements
Rank 1
answered on 02 Mar 2015, 12:17 AM
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). 
0
Roger
Top achievements
Rank 1
Veteran
answered on 31 Jul 2017, 07:36 AM

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;
}
0
Eyup
Telerik team
answered on 02 Aug 2017, 11:04 AM
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.
Tags
Grid
Asked by
Gernot
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Gernot
Top achievements
Rank 1
Rosen
Telerik team
Peter
Top achievements
Rank 1
Roger
Top achievements
Rank 1
Veteran
Eyup
Telerik team
Share this question
or