I am trying to fetch all records added today using DateDiff SQL syntax via Linq expression in MVC 5 / Entity Framework 6 application. DateDiff function throw runtime error
Actually i want to the following linq WHERE clause to parse with linq dynamics
.Where(p => DbFunctions.DiffDays(p.added_date, DateTime.Now) == 0)
in order to fetch today added records. Sample code that i am using shown below
var _list = new vsk_error_log();
using (var entities = new vskdbEntities())
{
_list = entities.vsk_error_log
//.Where("DateDiff(DAY,added_date,getdate())=0")
.Where(p => DbFunctions.DiffDays(p.added_date, DateTime.Now) == 0)
.ToList();
}
return _list;
Regarding Linq.Dynamic Expressions - how to write where clause
Dynamic WHERE clause in LINQ
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…