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 4571884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:34:04+00:00 2026-05-21T19:34:04+00:00

I am trying to write a dynamic search I and chain where clauses I

  • 0

I am trying to write a dynamic search I and chain where clauses I have my classes below and sample code.

public class Person
{
    public int PersonId { get; set; }
    //More Fields ..
}

//Link Table
public class PersonAddress
{
    public int PersonID { get; set; }
    public int AddressID { get; set; }
    //More Fields ..
}

public class Address
{
    public int AddressId { get; set; }
    public int ReferenceDataID { get; set; }
    //More Fields ..
}

public class ReferenceData
{
    public int ReferenceDataId { get; set; }
    public string MyData { get; set; }
    //More Fields ..
}


var query = (from p in People.Include("PersonAddresses")
 .Include("PersonAddresses.Address")
 .Include("PersonAddresses.Address.ReferenceData")
             select p);


if (!String.IsNullOrEmpty(searchName))
      query = query.Where(q => q.Search.Contains(person.SearchName));

// How can I access the MyData
if (!String.IsNullOrEmpty(searchCountry))
                query = query.Where(q => q.Search.Where(a => a. == "Ireland");

Thanks.

  • 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-21T19:34:04+00:00Added an answer on May 21, 2026 at 7:34 pm

    If you want to filter related records it is not possible when using includes. Include allows only loading all properties. The only possible way to get filtered navigation properties in single query is manual query with projection to non entity or anonymous type:

    var query = from p in context.Persons
                select new 
                {
                    Person = p,
                    Addresses = p.PersonAddreeses
                                 .Where(pa => pa.Address.Country == "Ireland")
                };
    

    If you want to get person which contains address from Ireland without filtering loaded addresses you cannot use query you defined. Where expects expression resulting in bool not another query. Try this:

    query = query.Where(p => p.PersonAddresses
                              .Any(pa => pa.Address.Country == "Ireland");
    

    I’m absolutely not sure what is Search in your example.

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

Sidebar

Related Questions

I'm trying to write dynamic method that calls Parallel.ForEach. I have checked a IL
I am trying to write a code in order to create dynamic textboxes. I
I'm trying write a query to find records which don't have a matching record
Im trying to write something to get my images to show correctly. I have
I'm trying to write a blog post which includes a code segment inside a
I am trying to do a dynamic search and replace with Perl on the
I am trying to write a Dynamic Query which uses a CTE. But I
I am trying to learn how to write more dynamic web sites that use
I'm trying to figure out how to write a dynamic URL (a.k.a. activationlink) in
ASP.NET MVC 2 I'm trying to write a view whose generic parameter is dynamic

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.