Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to format a Linq iQueryable query with a subquery

Posted on 2014-10-01
2
Medium Priority
?
489 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

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:…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

730 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