score:11

Accepted answer

your issue is not linq. your issue is that ef does not know how to convert that statement (z.joiningdate.addmonths(x.commitments.value)) to sql.

if you tolist() before the select it should work.

else you should use

entityfunctions.addmonths(z.joiningdate, x.commitments.value)

which ef can indeed convert to sql

in other words

.select(z => new bondcompletionviewmodel
{
   employeeid = z.employeeid.value,
   employeename = z.name,
   startdate = z.joiningdate,
   enddate =  entityfunctions.addmonths(z.joiningdate, x.commitments.value)
}).tolist();

edit: dbfunctions is the new ef 6 class to use instead of entityfunctions

score:1

you can use sqlfunction class:

.where(x => sqlfunctions.dateadd("month",x.commitments.value,x.joiningdate).month == todate.value.month)

score:4

you can use entityfunctions.addmonths

this function is translated to a corresponding function in the database.

usage

entityfunctions.addmonths(z.joiningdate, x.commitments.value)

Related Query

More Query from same tag