c# - Linq Regex for whole word search -
i'm unable find recent decent answer on this.
linq not support regex, , trying extract method out not outsmart framwork. how do whole work match on list of sentences in linq.
the reason need \b because start or end of string, or have comma, dash, or other similar separators.
private bool ismatch(string searchtext, string text) { return regex.ismatch(searchtext, "\\b"+text+"\\b", regexoptions.ignorecase | regexoptions.compiled); } result p = itemsrep .where(fulltext=> ismatch(searchtext, fulltext)) .firstordefault();
i think you're saying linq-to-sql/linq-to-entities not support regex
in expressions.
try adding .asenumerable()
before .where()
.
the .where()
method enumerate on results of translated query, rather try convert .where()
expression sql.
like this:
result p = itemsrep .asenumerable() .where(fulltext => ismatch(searchtext, fulltext)) .firstordefault();
Comments
Post a Comment