I have a Combobox with different conditions like "=", ">=", "<=" ... and dates. I would like to use the conditions in strings to compare dates. It's possible to convert the operators in string format to logical operators to compare dates on linq query to Oracle Database? I need dynamic conditions based on strings like "=", ">=" ...
1 Answer
You cannot compare a DateTime variable with a String variable.
So you need to create a DateTime. May design pattern can help a bit for your special case like Factory Pattern ;)
Look at
Here is a sample codes
var entity = dbContext.MyTable
.Where(w => DbFunctions.TruncateTime(w.SavedDateOnDb) == model.SelectedDate)
.First();
Another sample like this after ef6 :)
var list = db.MyClass.Where(c=> DbFunctions.TruncateTime(c.DbrecordDate)
> DbFunctions.TruncateTime(DateTime.UtcNow));
1 Comment
JuanDYB
I think that my question isn't clear. I want to convert string to operators, not to compare strings with dates.