开发者

Cannot perform an ORDERBY against my EF4 data

开发者 https://www.devze.com 2022-12-28 19:18 出处:网络
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 s

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
          开发者_如何学Python             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; }
}


Apparently having the OrderBy clause as a string is invalid (I thought I had tested that before?!). If I change my Linq query to the following, then it works:

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

This doesn't solve my problem but it does answer this specific question. I'll be posting another question related to my problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号