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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:11:37+00:00 2026-05-15T14:11:37+00:00

I have a fairly complex query where I am filtering results with a LIKE

  • 0

I have a fairly complex query where I am filtering results with a LIKE statement. Here is the query:

var qsFilter = entities.QueryStatements.Where("it.Statement LIKE @searchTerm", 
    new ObjectParameter("searchTerm", searchTerm));
var qtFilter = entities.QueryTables.Where("it.TableNames LIKE @searchTables", 
    new ObjectParameter("searchTables", searchTerm));

And then:

var tables = from t in entities.TraceLines
    join qs in qsFilter on t.QueryStatementHash equals qs.QueryStatementHash
    join qt in qtFilter on qs.QueryTableHash equals qt.QueryTableHash
    where t.CallTypeId == 64
    orderby t.Sequence
    select new
    {
        Name = qt.TableNames
    };

The problem is that in the final query, it generates an AND clause for the 2 LIKE filters:

WHERE ([Filter1].[Statement] LIKE @searchTerm) AND 
    ([Extent3].[TableNames] LIKE @searchTables)

How do I get that to be an OR clause?

Note: if you are wondering why I am using ESQL here, it is because of this: How to use SQL 'LIKE' with LINQ to Entities?

  • 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-15T14:11:37+00:00Added an answer on May 15, 2026 at 2:11 pm

    Although my LinqToEntities experience is limited, my reading of the reference materials suggests this might work:

    var joins =
      from t in entities.TraceLines 
      join qs in entities.QueryStatements
        on t.QueryStatementHash equals qs.QueryStatementHash 
      join qt in entities.QueryTables
        on qs.QueryTableHash equals qt.QueryTableHash
      select new {t, qs, qt};
    
    var filtered = joins
      .Where("it.Statement LIKE @searchTerm OR it.TableNames LIKE @searchTables"
        new ObjectParameter("searchTerm", searchTerm)
        new ObjectParameter("searchTables", searchTerm))
      .Where(x => x.t.CallTypeId == 64)
    
    var orderedAndProjected =
      from x in filtered
      order by x.t.Sequence
      select new 
      { 
        Name = qt.TableNames 
      };
    

    I’m baffled at what the “it” is for in those opaque strings. What a strange choice of codeword.


    Of course, if you switch to LinqToSql, you can simply write this (but you already knew that):

    var query = 
      from t in myDC.TraceLines
      from qs in t.QueryStatements
      from qt in qs.QueryTables
      where t.CallTypeId == 64
      where SqlMethods.Like(qs.Statement, searchTerm)
         || SqlMethods.Like(qt.SearchTables, searchTerm)
      order by t.Sequence
      select new
      {
        Name = qt.TableNames
      };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly complex LINQ to Entities query I'd like to try compiling
I have a fairly complex query that looks something like this: create table Items(SomeOtherTableID
I have a fairly complex Linq query: var q = from eiods in LinqUtils.GetTable<EIOfficialDesignee>()
I have a fat GUI that it getting fairly complex, and I would like
I have a fairly complex query that will be referencing a single date as
I have a fairly complex query (that includes a table valued function to allow
I have a fairly complex SQL query that pulls different types of products from
I have a fairly complex CLR stored procedure. What is the best way to
Our users have created MS-Excel spreadsheets which over time have evolved into fairly complex
I have a fairly complex (or ugly depending on how you look at it)

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.