Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C#
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
                                };
Posted
Updated 24-Jan-12 20:36pm
v2

 
Share this answer
 
v2
Comments
Anuja Pawar Indore 25-Jan-12 2:54am    
Added link
Hi,
try this ...
LINQ orderby on date field[^]
 
Share this answer
 
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
 
Share this answer
 
Comments
priya from Madras 25-Jan-12 6:19am    
Again am using lik this but it doesnt display in descending order.

pls Help me , am i wrong ?



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().OrderByDescending(x=>x.RestaurantIndex_Id);
return orderitembyrestaurant.ToArray();
}
C#
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().OrderByDescending(x=>x.RestaurantIndex_Id); 
    return orderitembyrestaurant.ToArray();
}

its working fine thanks all

[edit]pre tag for C# code added - PES[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900