Lets assume that I have a SQL Server database and a table which looks like:
Id int NOT NULL,
Date date NOT NULL
I have corresponding entity framework model:
public class Bundle
{
public int Id {get; set;}
public DateTime Date {get; set;}
}
User can type a string that can be anything. I need to find all items where Date, or any part of date, contains string entered by user. So, basically, I need to perform query:
SELECT Id, Date
FROM Bundles
WHERE Date LIKE '%user_query_here%'
My first attempt was
query.Where(b => b.Date.ToShortDateString().Contains(filter.Date))
This throws a NotSupportedException, so I tried this:
query.Where(b => Convert.ToString(b.Date).Contains(filter.Date));
Please note, that filter.Date is string. Its not a DateTime structure.
This also throws an exception. So my question is how execute query written above?
PS: I can't perform filtering in memory, this table has many thousands of rows.