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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:30:58+00:00 2026-05-23T16:30:58+00:00

I have a generic repository for my EF. It is working perfectly fine. But

  • 0

I have a generic repository for my EF. It is working perfectly fine. But today I found out that I need to get result that is not the exact match, instead it should be like the ‘LIKE’ of SQL where it gets anything that has the matching suffix or prefix of a column. Right now what it does is the Equal Operator. How can I tweak this code to behave like a LIKE instead of equal?

public IList<TEntity> SelectManyByColumnKeywordLike(string Key, string columnName)
{

    // First we define the parameter that we are going to use the clause. 
    var xParam = Expression.Parameter(typeof(TEntity), typeof(TEntity).Name);
    MemberExpression leftExpr = MemberExpression.Property(xParam, columnName);
    Expression rightExpr = Expression.Constant(Key);
    BinaryExpression binaryExpr = MemberExpression.Equal(leftExpr, rightExpr);
    //Create Lambda Expression for the selection 
    Expression<Func<TEntity, bool>> lambdaExpr =
    Expression.Lambda<Func<TEntity, bool>>(binaryExpr,
    new ParameterExpression[] { xParam, });
    //Searching ....
    IList<TEntity> resultCollection = ((IADRRepository<TEntity, TContext>)this).SelectAll
                (new Specification<TEntity>(lambdaExpr));
    if (null != resultCollection && resultCollection.Count() > 0)
    {
        //return valid single result 
        return resultCollection;
    }//end if 
    return null;
}
  • 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-23T16:30:59+00:00Added an answer on May 23, 2026 at 4:30 pm

    Like is represented in linq-to-entities with:

    • Contains("something") for representing LIKE '%something%'
    • EndsWith("something") for representing LIKE '%something'
    • StartsWith("something") for representing LIKE 'something%'

    So your method needs to know what type of LIKE you want to use and create correct expression to represent:

    • context.YourEntities.Where(e => e.Column.Contains(key))
    • context.YourEntities.Where(e => e.Column.EndsWith(key))
    • context.YourEntities.Where(e => e.Column.StartsWith(key))
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method to get a generic repository out of a dictionary: public
I have created Generic Repository and I have two entities that i need to
I currently have a complete generic repository but I'm missing one feature and that
I have a repository class that inherits from a generic implementation: public namespace RepositoryImplementation
I have a generic repository that is using Entity Framework 4 with the DbContext
I have an interesting situation where certain things are working but others are not
I am working with EF generic repository and have this function. public IEnumerable<T> Query(Expression<Func<T,
I have a generic repository that I use for common things such as FetchAllData,
I have a generic repository as like that public class Repository<T> : IRepository<T> where
I'm working with EF5 and I have a generic repository with a GetById method

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.