Only last Order clause used

Only last Order clause used

Postby coeamyd » Wed 20 Jun 2012 08:54

Hi everyone,

I have been using Linq-to-SQL for quite a while and now switched to dotConnect for Oracle using Entity Framework 4. I have several queries, where the user can select the field to sort on. I also apply a default sorting on several other columns. With Linq-to-SQL I was able to do something like this:

Code: Select all
// apply default sort
query = query.OrderBy(it => it.ColA).ThenBy(it => it.ColB);

switch (sortKey) {
    case "ColC": query = query.OrderBy(it => it.ColC); break;
    case "ColD": query = query.OrderBy(it => it.ColD); break;
}


This would result in the last Order clause being the first to sort by, and the default sort being applied afterwards, i.e. "ORDER BY ColC, ColA, ColB". With dotConnect for Oracle, however, only the last OrderBy seems to be taken into account. When I use the ObjectQuery.ToTraceString method, I only get ORDER BY ColC or something similar. ColA and ColB are simply ignored.

I know, the simple workaround is to simply add the default sorting to all the sort operations, but this results in much less maintainable code and a bunch of redundancy. So, I was wondering, whether this might be a bug, that might be fixed in the near future.

Thanks,
Christoph
coeamyd
 
Posts: 9
Joined: Fri 04 Nov 2011 14:59

Re: Only last Order clause used

Postby Shalex » Sat 23 Jun 2012 12:28

coeamyd wrote:When I use the ObjectQuery.ToTraceString method, I only get ORDER BY ColC or something similar. ColA and ColB are simply ignored.

This is a limitation of Entity Framework itself. If you try using System.Data.SqlClient against SQL Server, you will obtain a similar SQL generation.

Entity Framework and LINQ to SQL can behave in different ways. If you want to preserve a LINQ to SQL behaviour, we recommend you to migrate to LinqConnect which is fully compatible with LINQ to SQL. LinqConnect also has a better performance, additional functionality, wide database support (Oracle, SQL Server, etc) and other features.
Shalex
Devart Team
 
Posts: 7839
Joined: Thu 14 Aug 2008 12:44

Re: Only last Order clause used

Postby coeamyd » Sat 23 Jun 2012 14:11

Hi Shalex,

thanks for your input. I just verified this behavior with EF to SqlServer and you are absolutely right. EF always astonishes me in how lacking it is compared to LINQ-to-SQL. I guess, I'll have to live with the workaround for now. We are too far into the project to switch now.

Thanks,
Christoph
coeamyd
 
Posts: 9
Joined: Fri 04 Nov 2011 14:59


Return to dotConnect for Oracle