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

  • Home
  • SEARCH
  • 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 6958987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:12:45+00:00 2026-05-27T15:12:45+00:00

I am using EF Code first 4.2, What sort of solution do you propose

  • 0

I am using EF Code first 4.2,
What sort of solution do you propose when the where clause needs to be dynamically built?
Yet Include functionality would be highly required:

var results = db.Set<dynamicType>.Where("dynamic conditions").Include("....");

The dynamic condition above needs to lookup to another table to filter the records:
If I wanted to write that in Linq expression it would be something like:

var result = db.Set<Contact>().Where(c=>c.AccountId == _Id_param || db.Set<LinkTable>().Any(a=>a.FkFieldId == c.AccountId && a.ParentId == _Id_param)).Include("Quotes");

I basically needs the dynamic linq of the above expression, since for different types the Where clause fields changes (Contact is only an example), for example in one Model the FK field may be “AccountId” and in another it needs to be “AccountFKId”. So the Where clause has to be dynamic!

  • 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-27T15:12:46+00:00Added an answer on May 27, 2026 at 3:12 pm

    UPDATE

    I was able to solve the issue with directly modifying the expression tree.

    Using an idea from TomasP’s blog helped a lot:

    The key was to create a second IQueryable for the internal query and then pass it as an expression to the existing dynamic model’s IQueryable expression.

    IQueryable<LinkTable> linkQuery = db.Set<LinkTable>().AsQueryable();
    
    MethodCallExpression internalQueryWhere = Expression.Call(typeof(Queryable), "Where", new Type[] { linkQuery.ElementType }, linkQuery.Expression,Expression.Lambda<Func<LinkTable, bool>>(myfilters, new ParameterExpression[] { filterParameter })); 
    
    linkQuery = linkQuery.Provider.CreateQuery<LinkTable>(internalQueryWhere);
    
    Expression anyMethodExpr = Expression.Call(typeof(Queryable), "Any", new Type[] { linkQuery.ElementType }, linkQuery.Expression);
    

    Now you can pass the anyMethodExpr to the original Entity’s IQueryable where clause.

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

Sidebar

Related Questions

I have an AXIS2/JAX-WS web service using a code first implementation (yes I know,
I'm using the STL map data structure, and at the moment my code first
I have been using this code with great success to pull out the first
A bit of background first: I am using base code from a remote SVN
I am trying to parallelise a code using scala actors. That is my first
I am using the following code to get an alphabetic number of a first
After checking out code for the first time from a repository into Eclipse using
Let me first put the code snippets here. I am just using the ASP.NET
How to get the first child id inside the div using JQuery. Sample code:
This questions involves 2 different implementations of essentially the same code. First, using delegate

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.