c# - How to get around 'Only Parameterless constructors and initializers...' error -
i trying write linq query returns rows "datedue" field less 8 days current date. datedue field can null. here's query:
var employees = (from u in session.context.users bring together cu in session.context.companyusers on u.userid equals cu.userid bring together c in session.context.companies on cu.companyid equals c.companyid bring together uc in session.context.usercourses on cu.companyuserid equals uc.companyuserid bring together crs in session.context.courses on uc.courseid equals crs.courseid bring together in session.context.servicesoffereds on crs.servicesofferedid equals so.servicesofferedid bring together jt in session.context.jobtitles on u.jobtitleid equals jt.jobtitleid allow daysbeforeexpiring = (new datetime( datetime.now.year, uc.datedue.hasvalue ? uc.datedue.value.month : datetime.now.month, uc.datedue.hasvalue ? uc.datedue.value.day : datetime.now.day) - datetime.now).totaldays daysbeforeexpiring < 8 c.parentid == companyid || c.companyid == companyid cu.isactive uc.passed == false && uc.datedue > datetime.now && uc.datecompleted == null select new noncompliantemployeesmodel() { userid = u.userid, usercourseid = uc.usercourseid, jobtitle = jt.jobtitle1, companyid = cu.companyid, companyname = c.companyname, firstname = u.firstname, lastname = u.lastname, state = u.state, emailaddress = u.emailaddress, isactive = cu.isactive, serviceoffered = so.servicename, duedate = uc.datedue, days = daysbeforeexpiring });
but when run project, only parameterless constructors , initializers supported in linq entities.
error message. believe has fact i'm creating new datetime
object in query don't know how around it.
any help/guidance appreciated.
instead of using let
clause @ all, might want consider using datediff function of sqlfunctions
class, built doing more complex linq entities queries. namely, want doing next in where
clause:
where sqlfunctions.datediff("day", datetime.now, uc.datedue) < 8
the best part of function, in opinion, fact datetime
parameters nullable, won't need bother making null check first.
c# linq linq-to-entities
No comments:
Post a Comment