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

The Archive Base Latest Questions

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

I need to make a filter to search in a column of a table

  • 0

I need to make a filter to search in a column of a table in sql.

I have two methods, the first one receive a string(Name or LastName) and return a Collection<Employee>.

         public ICollection<Employee> GetEmployee_ByName(string Name)
         {
           ICollection<Employee> employee;
           using (ISession session = NHibernateSessionBuilder.OpenSession())
           {
              employee = session.CreateCriteria(typeof(Employee)).Add(Restrictions.Eq("Name", Name)).List<Employee>();
              if (employee.Count == 0)
              {
                employee = session.CreateCriteria(typeof(Employee)).Add(Restrictions.Eq("LastName", Name)).List<Employee>();
              }
               return employee;
            }
          }

The problem is with CreateCriteria(typeof(Employee)).Add(Restrictions.Eq("LastName", Name)) if the method receive a string for example: “Woods” and in the Column LastName the record for this Item is “Woods Taylor” that not return nothing, because that need are Equal to the column.

Or for example “Maikol Smith” and in the column the record is “Maikol Smith Jonhson” that not return nothing.

So, what can I do in this case?. To make a good filter.

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

    Use Like instead of Eq…

     employee = session
        .CreateCriteria(typeof(Employee))
        .Add(Restrictions.Like("LastName", "%" + name + "%"))
    

    Your current code generates SQL like the following:

    select ... from ... where LastName = 'Woods'
    

    By using Like instead of Eq, you generate SQL like the following:

    select ... from ... where LastName like '%Woods%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to filter alphabetic and non alphanumeric characters from a string to make
I want to make first user became admin. So I have string attribute admin
I need to make a moderate system like the one in fmylife.com. Basically the
I need to make a series (1-20) ajax calls and I need to have
This is a bit urgent! I'm trying to make a simple filter search where-by
I have a situation in my project where i need to make a redirection
Basically, I'm using WebGrid and I need to filter the results. The first problem
I am trying to make search on my database using Solr, and i need
I have a JSON string which includes a function I need to call. My
I need to make a custom filter on productCollection based on a specific tag.

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.