When doing an EF Core query with StartsWith
, then space is not included e.g. this query (notice space after Bob):
var query = _context.Persons
.Where(p => p.FullName.StartsWith("Bob ")
.Select(p => p.FullName);
will include Bobby, Bobfish and Bobwhatever because the SQL uses LEN('Bob ')
that is 3 because LEN does not include trailing spaces.
What is the trick to include spaces?
You can try using LIKE
explicitly via EF.Functions
:
var query = _context.Persons
.Where(p => EF.Functions.Like(p.FullName, "Bob %"))
.Select(p => p.FullName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With