locked
implement cross apply in linq RRS feed

  • Question

  • User1184281746 posted

    hi dear ,

     I want write this script in linq .How can i do it ?

       select * from [shop].Orders o
                cross apply(
                select top 1 * from [shop].Status_Order so where o.OrderID = so.OrderID and so.StatusID =28
                order by so.CreatedDate desc
                )as temp
                    

    please help me

    Tuesday, May 19, 2015 3:35 AM

Answers

  • User1711366110 posted

    hi nazlin,
      As per this case, you can try like below :

    var query = from a in shop.Orders
                from b in shop.Status_Order
                   .Where(x => x.OrderID == a.OrderID)
                   .OrderByDescending(x => x.CreatedDate )
                   .Take(1)
                where b.StatusID = 28 
                select new
                {
                  a.col1,
    	      a.col2,
    	      a.col3,
                  b.col1,
    	      b.col2,
    	      b.col3
                };
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 19, 2015 10:21 PM