I have the following asp.net core LINQ code:
List<UserSearchResult> results = await db.ApplicationUsers.Where(u => u.Name.StartsWith(name) && !u.Deleted && u.AppearInSearch)
.OrderByDescending(u => u.Verified)
.ThenBy(u => u.DateAdded) // Added to prevent duplication of results in different pages
.Skip(page * recordsInPage)
.Take(recordsInPage)
.Select(u => new UserSearchResult()
{
Name = u.Name,
Verified = u.Verified,
PhotoURL = u.PhotoURL,
UserID = u.Id,
Subdomain = u.Subdomain
}).ToListAsync();
Unfortunately this translates to the following:
SELECT [t].[Name], [t].[Verified], [t].[PhotoURL], [t].[Id], [t].[Subdomain] FROM ( SELECT [u0].* FROM [AspNetUsers] AS [u0] WHERE ((([u0].[Name] LIKE @__name_0 + N'%' AND (CHARINDEX(@__name_0, [u0].[Name]) = 1)) OR (@__name_0 = N'')) AND ([u0].[Deleted] = 0)) AND ([u0].[AppearInSearch] = 1) ORDER BY [u0].[Verified] DESC, [u0].[DateAdded] OFFSET @__p_1 ROWS FETCH NEXT @__p_2 ROWS ONLY ) AS [t]
I wonder why it has this part:
(CHARINDEX(@__name_0, [u0].[Name]) = 1)) OR (@__name_0 = N''))
and not only LIKE
Thanks a lot