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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:49:18+00:00 2026-05-10T22:49:18+00:00

I am trying to convert this test code to C# and having a problem

  • 0

I am trying to convert this test code to C# and having a problem with the Trim command. Has anyone done anything similiar like this in C# going to use this with a text box for searching the aspx page.

Dim q = From b In db.Blogs _         Where b.BlogContents.Contains(txtSearch.Text.Trim()) Or _               b.BlogTitle.Contains(txtSearch.Text.Trim()) _         Select b 
  • 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-10T22:49:19+00:00Added an answer on May 10, 2026 at 10:49 pm

    What is the issue you are having? And what LINQ provider is this? An in-memory set (LINQ-to-Objects)? Or LINQ-to-SQL? Or LINQ-to-Entities?

    I suspect you are getting something about the db LINQ provider not knowing about Trim() – in which case, try doing the trim first:

    string s = txtSearch.Text.Trim(); var q = from b in db.Blogs         where b.BlogContents.Contains(s) || b.BlogTitle.Contains(s)         select b; 

    This addresses two three separate issues:

    1: captures: in the original, it is txtSearch that is captured into the query, which has complications; by evaluating the Trim first, it is s that is captured, which is a simple immutable string

    2: expression complexity: with expression-based LINQ (i.e. to a database), the entire expression (including .Text, .Trim, etc) is part of the expression. If the LINQ provider doesn’t recognise one or more of those, it will fail. By reducing it to a string first, all the LINQ provider needs to handle is a string, which every provider should be fine with.

    (added) 3: repeated computation: LINQ-to-Objects is very literal; if you ask it to use a complex operation in a Where (etc), it will, even if it is obvious that the answer is unchanged per row; i.e. txtSearch.Text.Trim() shouldn’t change per row, so why evaluate it per row? Evaluate it before the query and it is only done once.

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

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Stumbled on this: validates_format_of :domain_name, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix FYI: Rubular… May 12, 2026 at 12:48 am
  • Editorial Team
    Editorial Team added an answer It gets constructed and deconstructed every iteration. However, on the… May 12, 2026 at 12:48 am
  • Editorial Team
    Editorial Team added an answer The signature of that method states that it returns a… May 12, 2026 at 12:48 am

Related Questions

I am trying to convert numbers in the form 123456 to 123,456 which I
I'm trying to implement a data compression idea I've had, and since I'm imagining
Previously, I ran into a problem trying to share a type definition between my
In this tutorial I am reading , Dave Ward creates a page that shows

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.