Cannot perform an ORDERBY against my EF4 data

Posted by Jaxidian on Stack Overflow See other posts from Stack Overflow or by Jaxidian
Published on 2010-05-03T16:08:19Z Indexed on 2010/05/03 16:48 UTC
Read the original article Hit count: 194

I have a query hitting EF4 using STEs and I'm having an issue with user-defined sorting. In debugging this, I have removed the dynamic sorting and am hard-coding it and I still have the issue. If I swap/uncomment the var results = xxx lines in GetMyBusinesses(), my results are not sorted any differently - they are always sorting it ascendingly.

FYI, Name is a varchar(200) field in SQL 2008 on my Business table.

private IQueryable<Business> GetMyBusinesses(MyDBContext CurrentContext)
{

    var myBusinesses = from a in CurrentContext.A
                       join f in CurrentContext.F
                           on a.FID equals f.id
                       join b in CurrentContext.Businesses
                           on f.BID equals b.id
                       where a.PersonID == 52
                       select b;

    var results = from r in myBusinesses
              orderby "Name" ascending
              select r;

    //var results = from r in results
    //          orderby "Name" descending
    //          select r;

    return results;
}

private PartialEntitiesList<Business> DoStuff()
{
    var myBusinesses = GetMyBusinesses();
    var myBusinessesCount = GetMyBusinesses().Count();

    Results = new PartialEntitiesList<Business>(myBusinesses.Skip((PageNumber - 1)*PageSize).Take(PageSize).ToList())
                  {UnpartialTotalCount = myBusinessesCount};

    return Results;
}

public class PartialEntitiesList<T> : List<T>
{
    public PartialEntitiesList()
    {
    }

    public PartialEntitiesList(int capacity) : base(capacity)
    {
    }

    public PartialEntitiesList(IEnumerable<T> collection) : base(collection)
    {
    }

    public int UnpartialTotalCount { get; set; }
}

© Stack Overflow or respective owner

Related posts about linq-to-entities

Related posts about entity-framework-4