Hi! I have a simple object hierarchy:

[HierarchyRoot]
    public abstract class AbstractObject : Entity
    {
        [Field, Key]
        public Guid Id { get; private set; }
        ...
    }

    public abstract class BlogPost : AbstractObject 
    {
        [Field]
        public DateTime? PublishedOn { get; set; }
        ...
    }

    public sealed class Article : BlogPost
    {
    }

Then I am trying to receive 4 latest articles ordered by PublishedDate.

Query<Article>.All.OrderByDescending(a => a.PublishedOn).Take(4)

But instead of it I receive articles ordered by another field. SQL Profiler shows:

SELECT TOP 4 [a].[Id], [a].[TypeId], [a].[CreatedOn], [a].[CreatedBy.Id], [b].[Category.Id], [b].[Title], [b].[PublishedOn], [b].[TeaserImage.Id], [b].[SitePage.Id] FROM (SELECT [c].[Id], [c].[TypeId], [c].[CreatedOn], [c].[CreatedBy.Id] FROM [dbo].[AbstractObject] [c] WHERE ([c].[TypeId] IN (119))) [a] LEFT OUTER JOIN (SELECT [d].[Id], [d].[TypeId], [d].[Category.Id], [d].[Title], [d].[PublishedOn], [d].[TeaserImage.Id], [d].[SitePage.Id] FROM [dbo].[BlogPost] [d] WHERE ([d].[TypeId] IN (119))) [b] ON ([b].[Id] = [a].[Id]) LEFT OUTER JOIN (SELECT [e].[Id], [e].[TypeId] FROM [dbo].[Article] [e]) [f] ON ([f].[Id] = [a].[Id]) ORDER BY [b].[Category.Id] DESC;

Updated at 25.10.2009 18:41:13

Yes, it is very simple. Yesterday I found some problems with LINQ, but most of them were more complex and I found a way to simplify them. This issue was a reason of my registration on your site :)

This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by buck.

asked Oct 25 '09 at 02:50

Editor's gravatar image

Editor
46156156157


One Answer:

Nice... Query looks so simple... I'm apologize for this issue.

It looks like there is an issue in one of our plan rewriters that finally leads to picking up wrong column. We don't translate OrderBy "as is" - instead, we just setup "expected order" marks in initial query plan, propagate them up to the root provider (each RSE provider describes a single query plan operation) there and finally (after all the other plan transforms, including removal of redundant columns) setup the actual sorting providers exactly where the order is really necessary (e.g. before .First/.Take/.Skip or the root element). So in the end this is pretty complex... And it looks like there is some bug our tests don't expose.

We'll try to fix it on Monday and send you the updated version for testing.

answered Oct 25 '09 at 11:03

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Alexey Gamzov has just reported the bug is fixed, but I see 6 new tests are failing on build server now. He will handle this when he is back from lunch, and we will update nightly build immediately.

(Oct 25 '09 at 11:03) Alex Yakunin Alex%20Yakunin's gravatar image

The issue was fixed today, the nighly build published there resolves the problem. If you can't access it (no SMB license), please notify me.

(Oct 25 '09 at 11:03) Alex Yakunin Alex%20Yakunin's gravatar image

buck wrote: Thanks. But the issue is not fixed completely. If I use Skip(...) before Take(...) I don't get anything in sql "order by" clause.

(Oct 25 '09 at 11:03) Editor Editor's gravatar image

We are working on this right now.

I hope it will be fixed tonight.

(Oct 25 '09 at 11:03) Dmitri Maximov Dmitri%20Maximov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA