Solved

How to format a Linq iQueryable query with a subquery

Posted on 2014-10-01
2
396 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
Comment Utility
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
Comment Utility
That was perfect, thank you.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now