c# - LINQ to entites does not recognize Convert.ToDatetime method -


edit other answers link previous question's wont work me because either using 2 tables or know startdate looking for.

i have following linq query trying data table last 14 days. linq not recognize convert.todatetime method. query_date column type string , can't change it. how data need?

       var logs = (from bwl in db.useractivities        convert.todatetime(bwl.query_date) >= datetime.now.adddays(-14)                                                          select new                           {                               id = bwl.id,                               useremail = bwl.useremail                                                             }).tolist(); 

convert.todatetime works if query_date has proper format. if not, check string expression convertable format.

i tested below code , works fine when assume query_date form of datetime.tostring().

var logs = (from bwl in db.useractivities         datetime.now - convert.todatetime(bwl.query_date) <= timespan.fromdays(14)         select new         {             id = bwl.id,             useremail = bwl.useremail         }).tolist(); 

i tested where expression convert.todatetime(bwl.query_date) >= datetime.now.adddays(-14) , confirmed gives same result.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -