New Posts New Posts RSS Feed: orderby not working
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

orderby not working

 Post Reply Post Reply
Author
tj62 View Drop Down
Groupie
Groupie
Avatar

Joined: 21-May-2009
Location: Iceland
Posts: 81
Post Options Post Options   Quote tj62 Quote  Post ReplyReply Direct Link To This Post Topic: orderby not working
    Posted: 24-Sep-2009 at 1:57am
Hi,
I don't know if this is the right place for my question. If not please advice me what is thr right forum for it. I'm quite a newby in LINQ but with long experience with SQL...so I'm having a small learning curver barrier here.

I have a LINQ to entities query using navigation properties that is such:

var customerQ = (from c in _manager.EntPointGroupAccessSet

where c.p_userID == "jhon"

orderby c.p_pointGroup.p_customer.p_name

select c.p_pointGroup.p_customer).Distinct();

foreach( EntCustomer c in customerQ )

{

    Console.WriteLine( "Customer = " + c.p_name );

    Console.WriteLine();

}

This query is working perfectly except the orderby is not working the data output is unordered. Why is the orderby cluse ignored?
How can I modify the query to get the order by working?
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2009 at 11:40am
Originally posted by tj62

I don't know if this is the right place for my question. If not please advice me what is thr right forum for it.


Technically this is a LINQ question rather than a DevForce question, and you might get better answers on a LINQ forum somewhere.  But you can always ask. We (IdeaBlade staff) have to give priority to the DevForce questions, but sometimes we enjoy practicing our LINQ, too; and there are, of course, lots of other LINQ users on this forum who may help.

I believe the problem is that your query is ordering the entities -- whatever their type name -- coming out of EntPointGroupAccessSet rather than the Customers you ultimately project out. 

I created the following attempted analog of your query, targetting the NorthwindIB database that we ship with DevForce:

      var customerQ = (from od in _mgr.OrderDetails
                       where od.UnitPrice > 50
                       orderby od.Order.Customer.CompanyName
                       select od.Order.Customer).Distinct();

Like you, I get Customers not sorted by CompanyName.

But if I change the query to the following, I get the Customers sorted as desired:

      var customerQ = (from od in _mgr.OrderDetails
                    where od.UnitPrice > 50
                    select od.Order.Customer).Distinct()
                    .OrderBy(c => c.CompanyName);

The corresponding query with your types would look like this:

     var customerQ = (from c in _manager.EntPointGroupAccessSet
       where c.p_userID == "jhon"    
      
select c.p_pointGroup.p_customer).Distinct()
       .OrderBy(cust=>cust.p_name);


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down