0

Dear i want to search the user from database table when user was entered the value into search textbox by using LINQ in ADO.net

i have one search textbox ..when user enter any letter than search Username from table who's name contain this letter !

i have Code for this:-

[HttpPost]
    public ActionResult Userlist(string UserName)
    {
        var U_master = db.User_Masters.ToList();

        if (!string.IsNullOrEmpty(UserName))
            U_master = U_master.Where(a => a.Username.Contains(UserName)).ToList();   

        return PartialView("Userlist", U_master);
    }

By using this code i can search Username only Text box value will match with username of database table but i want to display all the username record from database when user was the entered only single letter of Username ..and display all the Username who's name contain this letter . please give format to write LIKE Query or give any example..!

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Michel jeams
  • 103
  • 5
  • 17

1 Answers1

3

You could use SqlMethods.Like(matchExpression,pattern)

var results = from c in db.costumers
              where SqlMethods.Like(c.FullName, "%"+FirstName+"%,"+LastName)
              select c;

The use of this method outside of LINQ to SQL will always throw a NotSupportedException exception.

Source: Taken from
Also take a look at this post

Community
  • 1
  • 1
DayTimeCoder
  • 4,294
  • 5
  • 38
  • 61