-1

I am currently using this to query data in SQL Server:

var query = db.Phrases.AsQueryable();
if (options.Romaji != null) query = query
            .Where(w => w.Romaji.Contains(options.Romaji));

How can I change this so that instead of looking for a row with a column with a string in it that it looks for a row with a column which starts with the string in options.Romaji?

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • Possible duplicate of [Problem with LINQ to Entities and String.StartsWith](http://stackoverflow.com/questions/990451/problem-with-linq-to-entities-and-string-startswith) – smoksnes Nov 29 '16 at 15:02
  • 2
    It sounds as you want to use `w.Romaji.StartsWith(options.Romaji)` – smoksnes Nov 29 '16 at 15:04

1 Answers1

1

You just need to use the StartsWith() method instead of contains.

query = query.Where(w => w.Romaji.StartsWith(options.Romaji));
Cameron
  • 2,574
  • 22
  • 37