不能对我的EF4数据执行ORDERBY [英] Cannot perform an ORDERBY against my EF4 data

查看:187
本文介绍了不能对我的EF4数据执行ORDERBY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询使用STEs击中EF4,我有一个用户定义排序的问题。在调试这个,我已经删除了动态排序,并且它是硬编码,我仍然有问题。如果我在 GetMyBusinesses()中交换/取消注释 var results = xxx 行,我的结果不会有任何不同的排序 - 他们总是将其排序升序。

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,名称是一个 varchar(200) 字段在SQL 2008在我的业务表。

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; }
}


推荐答案

显然有code> OrderBy 子句作为一个字符串是无效的(我以为我以前测试过?如果我将Linq查询更改为以下内容,那么它的工作原理是:

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.

这篇关于不能对我的EF4数据执行ORDERBY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆