Although ASP.NET MVC implements and makes a good use of Entity framework, for that I would suggest using LINQ queries. Such as,
var people = dbContext.GetPeople();
var person = (from p in people
where p.Name == requiredName
select p).ToList();
If that is not the case and you want to implement your own search, then this article of mine might help you,
How to search for related query inside the Database using ASP.NET[
^]. That requires an SQL statement to search for the related terms,
var requiredName = $"%{query}%";
var sqlStatement = "SELECT * FROM Persons WHERE [Name] LIKE @0";
var result = db.Query(sqlStatement, requiredName);
The ASP.NET way of doing this is a bit different, and this code has SQL Injection prevention method implemented. If you want to use objects in
SqlClient
namespace, then consider the
SqlParameter
objects.
System.Data.SqlClient Namespace[
^]
LINQ (Language-Integrated Query)[
^]