using regular expression / Remove special characters with linq to sql

Posted by Prasad on Stack Overflow See other posts from Stack Overflow or by Prasad
Published on 2010-05-28T18:28:01Z Indexed on 2010/05/28 18:32 UTC
Read the original article Hit count: 173

Filed under:
|
|

How can i use regular expressions with linq to sql in the asp.net mvc(C#) application?

The columns in my MSSQL table (Products) has some special characters like (, - % ',.....).

While searching for a product i need to search without that special chareters.

For ex.: I have a product say (ABC-Camp's / One), when i search for "abccamp", it should pull the product.

I am trying the query like:

from p in _context.pu_Products
     where p.User_Id == userId && p.Is_Deleted == false
     && p.Product_Name.ToLower().Contains(text.ToLower())
     select new Product
     {
           ProductId = p.Product_Id,
           ProductName = p.Product_Name.Replace("’", "").Replace("\"", ""),
           RetailPrice = p.Retail_Price ?? 0M,
           LotSize = p.Lot_Size > 0 ? p.Lot_Size ?? 1 : 1,
           QuantityInHand = p.Quantity_In_Hand ?? 0  
     }

But i need to search without any special characters...

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about regex