linq with entity order by desc

c# entity-framework linq

Question

I just want to order descending like this:

var query = from o in oEntite_T.ORDRE
            where o.DATE_CREE >= datedeb && o.DATE_CREE <= datefin
            orderby o.NO_ORDRE descending
            select o;

It does not order descending, and I also tried:

var query = (from o in oEntite_T.ORDRE
             where o.DATE_CREE >= datedeb && o.DATE_CREE <= datefin
             select  o).OrderByDescending(p => p.NO_ORDRE);

I got the same result. Is this because the component Devexpress?

linqServerModeSource_Ordre.KeyExpression = "NO_ORDRE;CODE_CLIENT";
linqServerModeSource_Ordre.QueryableSource = oOrdre_BL.Get_OrdreEntity(dateEdit_Deb_Ordre.DateTime, dateEdit_Fin_Ordre.DateTime);

gridControl_Liste_Ordres.DataSource = linqServerModeSource_Ordre;

My complete code:

public IQueryable<ORDRE> Get_OrdreEntity(DateTime datedeb, DateTime datefin)
{
    try
    {
        IQueryable<ORDRE> LesListe;
        Soft8Exp_ClientEntities oEntite_T = new Soft8Exp_ClientEntities();

        var query = (from o in oEntite_T.ORDRE
                     where o.DATE_CREE >= datedeb && o.DATE_CREE <= datefin
                     select  o).OrderByDescending(p => p.NO_ORDRE);
        //var query = oEntite_T.ExecuteFunction<ORDRE>("qf").;

        LesListe = query;
        return LesListe;
    }
    catch (Exception excThrown)
    {
        throw new Exception("Err_02", excThrown);
    }
}
1
2
12/4/2013 10:28:02 AM

Popular Answer

From the code I see that you return the query object to some external infrastructure (set DataSource property of a devexpress component). Then I'd day that this component just adds another .OrderBy to this query when it executes it object so your sorting is lost.

It seems to be very possible and logical since devexpress have their own sorting capabilities which seem to just override yours.

By setting DataSource you just provide a data set, and it is up to the component to add sorting, paging, etc.

So look at the component API in order to specify sorting that you need. Perhaps it has properties to do it.

1
12/4/2013 10:24:05 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow