简体   繁体   中英

Search including swedish characters html-encoded

We've got an EF6 MVC3 codeFirst-site. Our news consist of two entities. newsPost with the strings Header and Introduction and newsArticle with the string Body , all nvarchar max in db.

In newsPost a swedish ö is stored as an ö in DB, but in newsArticle we have both ö and ö stored (we're using ckEditor for the editing the body).

When the user sends a string searchword it's easy to search for matches in the posts, but for the articles I would like to search for both the searchword and the html-encoded searchword.

I guess I want to write something like this

var htmlEncodedSearchword= Html.Encode(searchword);
var postIds = context.News.Where(m => m.Body.Contains(searchword)||m.Body.Contains(HtmlEncodedSearchword)).OrderByDescending(x=>x.PublicDate).Select(x => x.PostId).ToList();

...but I can't figure out how to do.

There is a method WebUtility.HtmlEncode which does that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM