I use the projection of the query results on a custom type that is not part of the entity data model:
public sealed class AlgoVersionCacheItem : NotificationObject { public int OrderId { get; set; } public string OrderTitle { get; set; } public int? CurrentVersion { get; set; } public int CachedVersion { get; set; } public IEnumerable<int> AvailableVersions { get; set; } }
I want AvailableVersions sort in descending order. Therefore, I tried to add sorting for AvailableVersions in the projection:
return someQueryable .Select(version => new AlgoVersionCacheItem { OrderId = version.OrderId, OrderTitle = version.Order.Title, CurrentVersion = version.Order.CurrentAlgoVersionId, CachedVersion = version.Id, AvailableVersions = version .Order .AlgoVersions .Where(v => (allowUncommittedVersions || v.Statuses.Any(s => s.AlgoVersionStatusListItemId == ModelConstants.AlgoVersionCommitted_StatusId)) && v.Id != version.Id) .OrderByDescending(v => v.Id)
When sorting, query execution raises a System.Data.EntityCommandCompilationException with System.InvalidCastException as an internal exception:
Cannot start an object of type 'System.Data.Entity.Core.Query.InternalTrees.SortOp' to enter type 'System.Data.Entity.Core.Query.InternalTrees.ProjectOp'
Without .OrderByDescending(v => v.Id) everything works fine.
Is this another feature that is not supported in the Entity Framework, or am I missing something?
PS I know that I can sort items later on the client side, but I'm interested in sorting on the server side.
c # entity-framework entity-framework-6
Dennis
source share