Reputation: 16851
I need to filter fields that starts with a particular integer
or list of integers
. For example, When I enter an integer (ex: 1
), the query should return 1, 10, 119, 1187, 1098.
The following query
gives me all the Schools
that has an Id
of 1
. However, I need to modify it so it returns 1, 10, 119, 1187, 1098.
return await _dbContext.Schools.Where(c => c.Id == Convert.ToInt32(schoolId)).Take(5).ToListAsync() ;
Upvotes: 2
Views: 342
Reputation: 252
You could do something like this, assuming:
Id
is an intschoolId
is a stringreturn await _dbContext
.Schools
.Where(c => c.Id.ToString().StartsWith(schoolId)).Take(5).ToListAsync();
Upvotes: 1