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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:22:57+00:00 2026-05-31T09:22:57+00:00

I am trying to mimic below statement in Linq to SQL. WHERE (rtrim(posid) like

  • 0

I am trying to mimic below statement in Linq to SQL.

WHERE (rtrim(posid) like '%101' or rtrim(posid) like '%532')

I statement basically determine if posid ends with 101 or 532. In the above example I am only making 2 comparisons but their could be 1 to N comparisons all joined with OR. I store the comparison values (101,532,…) in a generic list that I send to my Linq to SQL method.

I have tried to mimic above SQL using a where clause unsuccessfully (example below):

var PosNum = new List<string>();
PosNum.Add("101");
PosNum.Add("532");
var q = (from a in context.tbl_sspos select a);
q = q.Where(p => PosNum.Contains(p.posid.Trim()));

The issue with the above where clause is that it tries to do an exact match rather I want an ends with comparison.

How would I mimic the SQL statement in Linq to SQL.
Thank You in advance for any help / advice you can provide.

  • 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-31T09:22:58+00:00Added an answer on May 31, 2026 at 9:22 am

    In EF 4 you can use the StartsWith / EndsWith methods by now. Might also work in LINQ to SQL.

    UPDATE
    Just realized that you are trying todo this against multiple values (PosNum), I don’t think that this is directly supported currently. You can however concatenate multiple Where()clauses to get the result.

    UPDATE 2
    As AdamKing pointed out concatenating the where clauses was filtering against all PosNum values, here is the corrected version:

    var baseQuery = (from a in context.tbl_sspos select a);    
    IEnumerable<YourType> q = null;
    
    foreach(var pos in PosNum)
    {
        if(q == null)
            q = baseQuery.Where(a => a.posid.EndsWith(pos));
        else
            q = q.Union(baseQuery.Where(a => a.posid.EndsWith(pos)));
    }
    

    This is not as pretty anymore, but works nonetheless.

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

Sidebar

Related Questions

I'm trying to mimic something similar to FB. Basically, users can post comments in
I am trying to mimic a finally like effect. So i thought i should
I am trying to mimic the functionality of the image below. I am working
I'm trying to mimic the following Java code: int[][] multi; // DIMENSIONS ARE UNKNOWN
I'm trying to mimic what every other tabular view does with the DataGridView control,
Trying to get my css / C# functions to look like this: body {
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I'm trying to mimic the Camera app transition from the front to back camera..

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.