none
NOT IN clause in linq RRS feed

  • Question

  • how can i make an NOT IN clause in linq, i have my code like this:

    Select * From PurchaseOrder Where POType = 2 and Status = 2  and  lastupdated >= '2013-02-28 09:09:15'  and StoreID = 25 AND (PONumber NOT IN(SELECT PONumber FROM Reclamos_Header WHERE (PONumber = PurchaseOrder.PONumber) AND (StoreID = PurchaseOrder.StoreID))) Order by PONumber


    • Edited by daniavil Friday, May 3, 2013 6:16 PM
    Friday, May 3, 2013 6:16 PM

Answers

  • try this query

    var query = 
            db.PurchaseOrder
              .Where(po => po.POType == 2 && 
                     po.Status == 2 && 
                     po.lastupdated >= DateTime.Parse('2013-02-28 09:09:15') &&
                     po.StoreID == 25 &&
                     !(db.Reclamos_Header.Where(r => po.PONumber == r.PONumber &&
                                                    po.StoreID == r.StoreID)).Contains(PONumber)
                    )
            .OrderBy(po => po.PONumber)


    Please Mark as Answer and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.me/


    Saturday, May 4, 2013 9:48 PM