Solved

How to format a Linq iQueryable query with a subquery

Posted on 2014-10-01
2
414 Views
Last Modified: 2016-02-16
I have a query that looks like this:
return from delivery in db.Deliveries
                   where delivery.Sheets.Count == 0 && (delivery.Dealer.DealerName.ToString().Contains(kword) || delivery.Driver.DriverFirstName.ToString().Contains(kword) || delivery.Driver.DriverLastName.ToString().Contains(kword) || delivery.CreateDate.ToString().Contains(kword) || delivery.PONum.ToString().Contains(kword) || delivery.Initials.ToString().Contains(kword))
                   orderby delivery.CreateDate descending
                   select delivery;

There is a one to many relationship between Delivery and DeliveryParts. I would like to add a parts search to this query...something like:

return from delivery in db.Deliveries
                   where delivery.Sheets.Count == 0 && (delivery.Dealer.DealerName.ToString().Contains(kword) || delivery.Driver.DriverFirstName.ToString().Contains(kword) || delivery.Driver.DriverLastName.ToString().Contains(kword) || delivery.CreateDate.ToString().Contains(kword) || delivery.PONum.ToString().Contains(kword) || delivery.Initials.ToString().Contains(kword) || (SELECT COUNT from DeliveryParts WHERE partnumber LIKE '%kword%' > 0 ))
                   orderby delivery.CreateDate descending
                   select delivery;


Any help would be appreciated.
0
Comment
Question by:AmyL
2 Comments
 
LVL 11

Accepted Solution

by:
louisfr earned 500 total points
ID: 40356390
You can use Any to check the existence of an item:
delivery.DeliveryParts.Any(part => part.partnumber.ToString().Contains(kword))

Open in new window

0
 

Author Closing Comment

by:AmyL
ID: 40362594
That was perfect, thank you.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question