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

ToDataSourceRequest overload not working as expected

2 Answers 129 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Mo
Top achievements
Rank 1
Mo asked on 22 Jul 2012, 08:46 PM
I am using the overload of ToDataSourceResult to postproceess my DBContext Entity into my model. However, I receive a LINQ error when I use it in the manner below. I know LINQ enough to understand the error, but I am confused because this forum post seemed to indicate the postprocessing expression would be used AFTER the object has been retrieved from the DBContext and not as part of the retrieval from the DBContext. Can you provide clarification?

My code:

DataSourceResult result = this.StateProvinceService
                .GetQueryable()
                .ToDataSourceResult<StateProvince, StateProvinceModel>(
                    request,
                    province => Mapper.Map<StateProvince, StateProvinceModel>(province));

The result:

LINQ to Entities does not recognize the method 'XYZ.Web.Areas.Admin.Models.StateProvinceModel Map[StateProvince,StateProvinceModel](XYZ.Model.StateProvince)' method, and this method cannot be translated into a store expression.

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 23 Jul 2012, 09:25 AM
Hello Morad,

 You are absolutely right! The projection function is currently being passed to the Select extension method of the IQueryable. This however means that EF would still complain when it finds code it cannot translate to SQL. We have now modified the behavior to first call ToList() and then execute the projection function in-memory. This change will be available in the next internal build which is due later today.

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mo
Top achievements
Rank 1
answered on 23 Jul 2012, 01:55 PM
Thanks Atanas!
Tags
Data Source
Asked by
Mo
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Mo
Top achievements
Rank 1
Share this question
or