How i use Contains for string in Linq to Sql to match only the beginning of a word
I can use linq to sql to match a part of a string with
F开发者_高级运维rom C In DB.City Where C.Name.Contains(Query)
What i need to do for it to match only beginning of words? (Behave like full text index)
You can check if the first word starts with the query by using StartsWith
instead of Contains
:
C.Name.StartsWith(Query)
This only checks the first word, not all words in the string.
You can't do a full text search directly using LINQ. What you can do instead is create a stored procedure to do the full text search and call that using LINQ.
Related question:
- Is it possible to use Full Text Search (FTS) with LINQ?
See also:
- LINQ to SQL - Enabling Fulltext searching
精彩评论