The mismatched data type would hurt the performance. This might look obvious at first, but if we take a closer look, it is evident that we should be addressing the concern. The following tweaked About
view component illustrates the retrieval of data using PhoneNumber
rather than Id
:
var aboutViewModel = _context.People
.Where(item => item.PhoneNumber.Equals("9876543210"))
//.Where(item => item.Id.Equals(id))
.Select(item => new AboutViewModel
{
Name = item.FirstName,
Biography = item.Biography
}).SingleOrDefault();
The preceding LINQ query would be translated into the following SQL query: enable Actual Execution plan
with the query execution, and it would be evident that something is wrong here. Whenever we have mismatched data types in a query, the data type conversion would enforce an index scan operation. In the following screenshot, we can see that the Clustered Index Scan is happening rather than performing a...