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

2
  • 2
    Look at this post Commented Aug 15, 2018 at 8:36
  • This was ok for me. Thanks! Commented Aug 20, 2018 at 22:05

1 Answer 1

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));
Sign up to request clarification or add additional context in comments.

1 Comment

I think that my question isn't clear. I want to convert string to operators, not to compare strings with dates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.