c# - Linq query error - Unable to cast object of type 'V1.Controllers.Loan' to type 'System.IConvertible -


in first query (stringquery) trying pass string date.

linq query 1:

 var stringquery = (from p in db.database_cre_events                     select new loan()                     {                         cdate = p.lastupdated                      }).firstordefault(); 

then convert string date first query datetime field dtt. because, in second query (datequery) need use date parameter (as datetime), in clause accepts datetime type field.

 if (stringdquery != null && stringdquery.cdate.hasvalue)        {            dtt = convert.todatetime(stringdquery);          } 

linq query 2:

   var datequery = (from p in db.database_cre_events.where(c => c.lastupdated == dtt)                     select new loan()                     {                         latest = p.date                      }).firstordefault(); 

however, when execute function - on client-side, thrown error – unable cast object of type 'stw_v1.controllers.loan' type 'system.iconvertible

error on following line:

dtt = convert.todatetime(stringquery);

am missing in code?

apology in advance, if above explanation not clear please feel free ask further questions.

thank you

because stringquery returns single loan object not implement iconvertible suspect meant cdate property form object instead:

if (stringdquery != null && stringdquery.cdate.hasvalue) {     dtt = convert.todatetime(stringdquery.cdate);  } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -