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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:36:46+00:00 2026-05-11T05:36:46+00:00

I have some predicates being dynamically built that have the following signature passes through

  • 0

I have some predicates being dynamically built that have the following signature passes through as parameters into a function:

Expression<Func<TblTableR, bool>> TableRPredicate, Expression<Func<TblTableN, bool>> suspectNamesPredicate, Expression<Func<TblTableS, bool>> TableSPredicate, Expression<Func<TblTableI, bool>> suspectTableIPredicate, 

I am trying to query using the following:

var registries = (from r in db.TblTableR.Where(TableRPredicate) join s in db.TblTableS.Where(TableSPredicate)          on r.TblTableRID equals s.TblTableSTableRID into ss from suspects in ss.DefaultIfEmpty()     join si in db.TblTableI.Where(suspectTableIPredicate)          on suspects.TblTableSIndexCardID equals si.TblTableIID into sisi     from suspectTableI in sisi.DefaultIfEmpty()     join sn in db.TblTableN.Where(suspectNamesPredicate)          on suspectTableI.TblTableIID equals sn.TblTableNIndexCardID into snsn     from suspectNames in snsn.DefaultIfEmpty()     select r.TblTableRID).Distinct(); 

This has the result of putting any generated ‘where’ clause into the JOIN statement eg:

left outer join tblTableI on tblTableITableRID = tblTableRID     AND (expression created by predicate) 

What is actually happening is that the final SQL that is created is incorrect. It is creating the following type of sql

 select * from table1 left outer join table2 on field1 = field2      AND field3 = 'CRITERIA' 

It is this AND clause on the end that is the problem – ending up returning too many rows. Essentially I would like to get the where clause into the statement and not have it stick the extra condition into the join.

Something like this:

select * from table1 left outer join table2 on field1 = field2      WHERE field3 = 'CRITERIA' 

I have tried adding a Where clause in as follows:

... ... ... select r.TblTableRID).Where(TableRPredicate).Distinct(); 

but that will not compile because of the generic parameters on each predicate.

If I modify my LINQ query to only select from one table and use a predicate, the WHERE clause is generated correctly.

Any ideas?

  • 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. 2026-05-11T05:36:47+00:00Added an answer on May 11, 2026 at 5:36 am

    (edited post clarification)

    Step 1; change the final select to select all three entities into an anonymous type; for me (testing on Northwind), that is:

    select new {emp, cust, order}; 

    Step 2; apply your filters to this using the extension method I’ve added below; for me this filtering looks like:

    var qry2 = qry.Where(x => x.emp, employeeFilter)             .Where(x => x.cust, custFilter)             .Where(x => x.order, orderFilter); 

    Step 3; now select the entity/entities you actually want from this filtered query:

    var data = qry2.Select(x => x.order) 

    And here’s the extension method:

    static IQueryable<T> Where<T,TValue>(     this IQueryable<T> source,     Expression<Func<T, TValue>> selector,     Expression<Func<TValue, bool>> predicate) {     var row = Expression.Parameter(typeof (T), 'row');     var member = Expression.Invoke(selector, row);     var lambda = Expression.Lambda<Func<T, bool>>(         Expression.Invoke(predicate, member), row);     return source.Where(lambda); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET function that does some complex calculation. Depending on the parameters
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
We have some files on our website that users of our software can download.
I have some NSOperations subclasses that handle CoreData imports. I believe i've ticked most
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I have some classes layed out like this class A { public virtual void
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to

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.