score:11
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)
Source: stackoverflow.com
Related Query
- How to add Month in date time and Compare with another date time in Linq?
- how to combine two columns Date and Time and compare it with given DateTime using linq
- Entity Framework: Linq where clause compare date and time value with seconds difference
- How can I select items with Linq by Date while ignoring Time portion of a DateTime property?
- How to compare only date part with linq expression?
- I wants to date month and year add 2 month later in linq
- How to sort linq with fixed values and show all the rest with another sorting
- c# find item in list returned by LINQ query and compare its value with another item in list
- how to compare string linq with sub query with another linq with sub query
- Group by year and month with given date range using Lambda or LINQ Query
- How to write a count and group by month query with linq
- how could i handle this linq query and compare it with and int in an if-statement?
- How do I use LINQ to compare a date and a datetime?
- How To add another constructor with parameter in linq class(Table)
- How to calculate STD dev and Average with linq and entity framework at the same time
- How to select a record and only it's children with the highest date in LINQ to SQL
- How can I add and remove records from a collection with LINQ
- Grouping data by timestamp date and time with linq
- How can I take a list of dates, and remove any that are within 1 minute of another date in the list with LINQ?
- How to match value from textbox to dictionary and display it in another textbox on button click with linq query in C#
- How to combine 2 lists containing csv strings and compare the result with another csv
- How to convert date to string and compare using Linq
- linq how to pull an int col and compare with 0
- How sum a column in Entity Framework using linq and join it with another table
- How to add hour from another column to date in Linq to SQL
- Convert sql to linq where incoming date and time . Need to add time HH
- How to add elements or nodes, to existing XML, given an input string to compare with - using a LINQ query
- C# Linq How do I filter a list with the data of an object and store the result in another list?
- how to query a record with latest date as part of another linq query
- C# Linq how to add each missing year and month to data
More Query from same tag
- Split List to Categories using Linq
- GroupBy Linq with Where Criteria
- .First does not throw exception on empty collection
- How to filter LINQ to SQL result by xref table property
- GroupBy loses ThenBy sort order
- Select one record using multiple group by and count
- Inserting records on multiple tables in a single method using Entity Framework
- How to GroupBy based on condition
- How can I convert a Predicate<T> to an Expression<Predicate<T>> to use with Moq?
- How to select multiple elements into array in Linq query?
- Linq to XML - Dynamic count of element items
- Linq Parsing Error when trying to create seperation of concerns
- Check Directories in C# using Linq
- Can an object be instantiated only once inside a linq query?
- LINQ - exclude the filter when the value is NULL
- Fetch data by upcoming birthdays in linq to sql
- Linq and EF: Querying to get results on one to many relationships: Selecting table with foreign Key
- Force a main Thread element to run in another created thread
- LINQ query to find related data
- How to group list of files (strings) by folder and perform select method on the group
- Combine two LINQ queries returning bool to one returning bool?
- netstandard1.0 /netstandard1.2 and LINQ
- remove from List using Linq
- Using LINQ in VB.NET with namespaces
- LINQ - how to make change tracking work when entity passed to another class as property
- Linq observable collection cast error
- LINQ to DataSet, error in getting char field
- ORA-00904 Linq generates error in SQL query for Oracle
- Combining multiple linq queries and concatenated results into a smaller query
- Moving ten files at a time using Vb.NET