Linq .contains for ints

Posted on 2012-09-11
Last Modified: 2012-09-11

I've got a search form:

Last Name:  [lastNameTextBox]
ID:  [idTextBox]

I process this search for by starting with a base linq query:

var query = from u in db.users
                    select u;

Next, I see if the user entered something into the last name text box and if they did, I append the information to the base linq query:
if (!string.IsNullOrEmpty(LastNameTextBox.Text))
      query = query.Where(t => t.LastName.Contains(LastNameTextBox.Text));

Open in new window

My problem is that I can't seem to get the part for the ID to work:

if (!string.IsNullOrEmpty(IDTextBox.Text))
      query = query.Where(t => t.ID.Contains(convert.toInt32(IDTextBox.Text)));

Open in new window

.Contains() doesn't seem to work, because I think .Contains() is for strings only.  Any idea how to get this to work?

C#.NET 4.0
Question by:adskarcox
    1 Comment

    Accepted Solution

    Looks like the .int equivalent is .equals

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now