ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Odropdown with remote search LINQ error
Title:
B
I
{code}
?
Hello, i am trying to reproduce "Odropdown with remote search" but getting following LINQ error: _LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method, and this method cannot be translated into a store expression._ Here is view code: @(Html.Awe().AjaxRadioList("RemoteSearchOdropdown") .Odropdown(o => o.SearchFunc("utils.osearch", Url.Action("SearchGoods", "QRRegistries"), "m1").ClearBtn()) .Value(32572) .Url(Url.Action("GetGoodsInit", "QRRegistries"))) and controller: public ActionResult GetGoodsInit(int? v) { var items = db.Goods.Where(o => o.idCategory != 6).Take(3).ToList(); var selected = db.Goods.SingleOrDefault(o => o.id == v); if (selected != null && !items.Contains(selected)) { items.Add(selected); } return Json(items.Select(o => new KeyContent(o.id, o.goodName))); } public ActionResult SearchGoods(string term = "") { var items = db.Goods .Where(o => o.goodName.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0) .Take(10) .Select(o => new KeyContent(o.id, o.goodName)); return Json(items); }
Save Changes
Cancel
Vladimir Kerzhentsev
asked at 14 Nov 2022
Answers
B
I
{code}
?
When using Entity Framework the linq code will be translated into SQL syntax, and not everything can be translated. Specifying `OrdinalIgnoreCase` is usually unnecessary with SQL Databases, because this is the default behaviour. Change your code to this: var items = (await db.Goods .Where(o => o.goodName.Contains(term)) .Take(10) .ToArrayAsync()) .Select(o => new KeyContent(o.id, o.goodName)); (you can also remove the `await`, and replace `ToArrayAsync` with `ToArray` )
Save Changes
Cancel
Omu
answered at 14 Nov 2022
Thank you very much, it works!
at 14 Nov 2022
Vladimir Kerzhentsev
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK