I don't find a way to make a search on IQueryable
object with LIKE %some%text%
operator like in SQL command.
At the moment I do this:
System.Data.Entity.DbSet<Shop> database_Shops = database.Shops;
string searched_shop = !String.IsNullOrEmpty(post_data["shop"]) ? post_data["shop"] : " ";
ViewBag.shops = database_Shops
.Where(shop => shop.Name.ToUpper().Contains( searched_shop.ToUpper()))
.Take(RESULTS_PER_PAGES * pageNumber);
But it don't find an entry without space in shop.Name
. Anyone know a way to do this?
Thank you very much!
You can use SqlMethod
in the namespace System.Data.Linq.SqlClient
:
database_Shops.Where(shop => SqlMethods.Like(shop.Name, "%some%text%"));
SqlMethods.Like Method (String, String)
In EF Context you can use SqlFunctions
in the namespace System.Data.Objects.SqlClient.SqlFunctions
database_Shops.Where(shop => SqlFunctions.PatIndex("%some%text%", shop.Name) > 0);
SqlFunctions.PatIndex Method (String, String)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With