Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to format a Linq iQueryable query with a subquery

Posted on 2014-10-01
2
Medium Priority
?
526 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

972 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