I have a linq which a simple where statement and a simple select. If i return the result as .ToList() everything works fine. If I change it to .ToDataSourceResult(request), I get exception with the error message "The specified type member 'Disabled' is not supported in LINQ to Entities only when using..." but I can't find where the 'Disabled' is coming from, and why this happens only for DataSourceResult. Any ideas why this is happening or how to solve this?
Here is my Code:
public ResponseData<DataSourceResult> GetMunicipalitiesDDL(DataSourceRequest p_request, string p_filterText)
{
var response = new ResponseData<DataSourceResult>();
try
{
using (var context = new DBEntities())
{
response.Data = (from x in context.MUNICIPALITY_VIEW
where x.AC_MUNICIPALITY != null
select new SelectListItem
{
Text = x.AC_MUNICIPALITY,
Value = x.AC_MUNICIPALITY
}).ToDataSourceResult(p_request);
}
}
catch (Exception ex)
{
response.Status = ResponseStatus.Unsuccessful;
response.Message = ex.Message;
}
return response;
}
I have found the solution here https://entityframework.net/knowledge-base/10159539/the-specified-type-member-is-not-supported-in-linq-to-entities--only-initializers--entity-members--and-entity-navigation-properties-are-supported.
What I did was I included the "Disabled" property in the select. I don't know why when using .ToDataSourceResult() I have to select "Disabled" but when using .ToList() it is ok.
My code now looks like this: