anthonypliu
anthonypliu

Reputation: 12437

How to make a simple search function in linq and EF

I want to simply search a database for a certain string, how can i accomplish this using linq and EF (if using these tools for it are not practical I am open to any suggestions). I just want to take a string and search my usernames, the search should be able to handle things only parts of the username (using some sort of 'contains' function)

Upvotes: 2

Views: 639

Answers (1)

Quintin Robinson
Quintin Robinson

Reputation: 82325

The basics of what you are asking is..

var found = MyContext.Users.Where(user => user.UserName.Contains(searchString));

You would need to substitute actual entity names/values for the example code posted.

Upvotes: 1

Related Questions