Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6646405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:24:45+00:00 2026-05-26T00:24:45+00:00

I am trying to return a result set that includes rows where any of

  • 0

I am trying to return a result set that includes rows where any of three strings has a string match. My domain models look like this:

public class Customers
{
    public int CustomerID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

public class BidNames
{
    public int BidNameID { get; set; }
    public int CustomerID { get; set; }
    public string BidName { get; set; }
}

There is a FK between BidName.CustomerID and Customers.CustomerID and it is a one-to-many relationship where there can be multiple BidNames for a single Customer. When searching my customer table I want to bring back all records where there is a string match in FirstName, LastName or any of the associated BidNames. For this example I’ll use a BidName search string of “ba”.

from c in Customers
where c.FirstName.Contains("ba") || c.LastName.Contains("ba") || c.BidNames.Any(b=>BidNames.BidName.Contains("ba"))
orderby c.LastName, c.FirstName
select new { CustomerID = c.CustomerID, FirstName = c.FirstName, LastName = c.LastName }

It all works until I add the final criteria in the Where clause. I understand that c.BidNames is a collection and I’m looking to see if Any of them have a BidName that contains “ba”. Where I’m running into trouble is trying to specify the BidNames.BidName column to search for the string. The code I’ve written above fails with “BidNames does not contain a definition for ‘BidName'”

How do I write the last part of the Where clause so I can search all the BidNames.BidName fields associated with the Customer record? I hope and assume I can use the same syntax to specify the BidName field in the orderby and select clauses as well.

Many thanks,

BK

FINAL ANSWER:

from c in Customers
where 
    c.FirstName.Contains("ba") || 
    c.LastName.Contains("ba") || 
    c.BidNames.Any(b=>b.BidName.Contains("ba"))
orderby 
    c.LastName, 
    c.FirstName
select new { 
    CustomerID = c.CustomerID, 
    FirstName = c.FirstName, 
    LastName = c.LastName,
    BidNames = c.BidNames.OrderBy(b=>b.BidName)
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:24:45+00:00Added an answer on May 26, 2026 at 12:24 am

    Try changing your where clause to

    Where c.FirstName.Contains("ba") || 
          c.LastName.Contains("ba") || 
          c.BidNames.Any(b=>b.BidName.Contains("ba"))
    

    In your Any clause, b is an instance of the BidNames class, so you want to access properties of that rather than the BidNames property of the Customer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to return the result that I found in my query to
I am trying to return a result set from a MySQL database table of
Im trying to get a result set that contains the 10 values that are
I'm trying to run a LINQ to SQL query that returns a result in
im trying to return a string value from a method inside my script tag
Im trying to return the value that a $ajax call returns, from a function
Im trying to return a SimpleQuery list that queries a single table and uses
When trying to return a simple set of results from my database table 'checklist'
I'm trying to take my result set and send it to the view so
I'm trying to create an algorithm that set some relevance to a webpage based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.