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 "=", ">=" ...
Asked
Active
Viewed 377 times
0
-
2Look at [this post](https://stackoverflow.com/questions/7086058/convert-string-value-to-operator-in-c-sharp) – Nick Suslov Aug 15 '18 at 08:36
-
This was ok for me. Thanks! – JuanDYB Aug 20 '18 at 22:05
1 Answers
0
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));

Eyup Can ARSLAN
- 692
- 9
- 25
-
I think that my question isn't clear. I want to convert string to operators, not to compare strings with dates. – JuanDYB Aug 15 '18 at 07:34