I have an item in db with this content:
B & b / v (stärrfood) - 1,0l
And this:
var item = (from x in db.tblMyTable where x.item_name == "B & b / v (stärrfood) - 1,0l" select x).First();
returns that there is no such item. I think it’s because of the ä. What to do?
If your DB item actually reads
and not
then the problem is clear; the strings inside your DB have been HtmlEncoded. So the actual question is how to get from the second string, to the first.
Usually I would recommend:
and searching for the encoded variable instead. However, the result of
HtmlEncode()is close but not exactly equal to your DB record. TheHtmlEncode()uses the numeric entities instead of the alphabetic version.But this might give you a clue as to how to solve the problem. Still I’d highly recommend not searching for string but using a numeric PK value instead. This problem can be quite difficult to solve I think.