Convert String to linq condition Entity Framework core

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

Popular Answer

A DateTime variable and a String variable cannot be compared.

Therefore, you must build a DateTime. For your unique situation, a design pattern like the Factory Pattern would be helpful;)

Look at

DbTransectionFunctions

Here is an example of a code.

var entity = dbContext.MyTable
    .Where(w => DbFunctions.TruncateTime(w.SavedDateOnDb) == model.SelectedDate)
    .First();

After ef6, another example in this style is:

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