Convert String to linq condition Entity Framework core

.net-core entity-framework-6 entity-framework-core-2.1 linq

Question

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
0
8/15/2018 7:36:47 AM

Popular 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

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));
0
8/15/2018 7:02:54 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow