Solved

How to format a Linq iQueryable query with a subquery

Posted on 2014-10-01
2
438 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net SQL Query 2 Tables Different Databases 3 43
Asp.Net Session Question 2 33
YouTube API get the Video Tags - vb.net 7 24
C# LINQ 5 18
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…

685 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