简体   繁体   中英

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM