如何在linq中按降序绑定数据 [英] how to bind the datas in descending order in linq

查看:75
本文介绍了如何在linq中按降序绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何按降序绑定数据,实际上是在linq中使用lik this到sql

但它不起作用,默认情况下显示,我该怎么办?

How to bind the datas in descending order,actually am using lik this in linq to sql

but its not working , it shows by default , wat shall i do?

var orderItems = from od in db.OrderDetails
                                where od.RestaurantIndex_Id == restaurantOrder.RestaurantIndex_Id  orderby od.OrderIndex_Id descending
                               restaurantOrder.OrderIndex_Id
                                select new
                                {
                                    OrderDetailId = od.OrderDetailId
                                };

推荐答案

尝试使用此链接可以为您提供帮助
http://stackoverflow.com/questions/5344805/linq-orderby-descending-query
try this link it helps you
http://stackoverflow.com/questions/5344805/linq-orderby-descending-query



试试这个...
日期上的LINQ订购依据 [
Hi,
try this ...
LINQ orderby on date field[^]


公共DinnerNow.Business.Data .RestaurantOrder [] GetPreOrderDetails(字符串RestaurantName,字符串DeliveryType,字符串restaurantownerid)
{

var orderItems =从db中的od.OrderDetails
其中od.RestaurantIndex_Id == restaurantOrder.RestaurantIndex_Id订单由od.OrderIndex_Id降序
restaurantOrder.OrderIndex_Id
选择新
{
OrderDetailId = od.OrderDetailId
};. Distinct();
return orderitembyrestaurant.ToArray();
}


上面的代码中的代码仅在不使用Distict()的情况下才能解决问题,但它显示重复的值.我不能同时使用Distinct()和OrderByDescending()这两种方法,那么怎么可能.

救救我
public DinnerNow.Business.Data.RestaurantOrder[] GetPreOrderDetails(string RestaurantName, string Deliverytype, string restaurantownerid)
{

var orderItems = from od in db.OrderDetails
where od.RestaurantIndex_Id == restaurantOrder.RestaurantIndex_Id orderby od.OrderIndex_Id descending
restaurantOrder.OrderIndex_Id
select new
{
OrderDetailId = od.OrderDetailId
};. Distinct();
return orderitembyrestaurant.ToArray();
}


in the above code can resolve the problem only when the Distict() is not used ,but it display the duplicate value .i cant able to use the both method Distinct() AND OrderByDescending(),Then how should its possible .

Help me


这篇关于如何在linq中按降序绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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