0

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 "=", ">=" ...

JuanDYB
  • 590
  • 3
  • 9
  • 23

1 Answers1

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

DbTransectionFunctions

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