+ Reply to Thread
Results 1 to 2 of 2

Thread: translating from sql to linq

  1. #1

    translating from sql to linq

    I have that SQL query , and i`d like to translate it to LINQ :
    select t.* from items t
    left outer join (
        select od.itemid, ct = COUNT(1)
        from orderdetails od
            join orders j on od.orderid = j.orderid
        where j.ordersubmitteddate is not null
        group by od.itemid
        ) pop on pop.itemid = t.itemid
    order by pop.ct desc, t.name
    EDIT :
    I want to display all the items, but in order of popularity.
    Last edited by basemhosam; 01-27-2012 at 03:37 PM.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    var items = db.Items.Where("Thing");
    items = from t in items
            join pop in (
                from od in db.OrderDetails
                where od.Order.OrderSubmittedDate != null
                group od by od.ItemId into g
                select new { ItemId = g.Key, Ct = g.Count() }
            ) on t.ItemId equals pop.ItemId into pop_join
            from x in pop_join.DefaultIfEmpty()
            orderby x.Ct descending, t.Name
            select t;

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts