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
- linq distinct on two columns and return as a single field
- Turning an IEnumerable of IEnumerables into a dictionary
- Structuring models in a simple hierarchy in MVC, what's the best practice?
- I am trying to return a True or false if a given directory contains ".exe"
- EF 4.1, database first and Many-to-Many relationships - How to get all sub-objects?
- Linq produce a list of missing records for a given date range
- Compare DateTime in EF Core Linq Query
- Linq subtraction sum(values) from two tables
- LINQ To Entities - M to M selection returns more columns than needed
- Xdocument.Load(XMLReader.Read()) Is giving me erros
- Select multiple times using LINQ based on result
- How to use count in linq
- Parsing XML with multiple similar child nodes in C#
- LINQ not updating on .SubmitChanges()
- Join string with same property using LINQ
- ASP.NET MVC - How do I implement Paging?
- Get items from List A where Id is common in both List A and List B and counter of that Id is more than 1 in List A or List B
- Wrong query generated with entity framework
- linq where clause and count result in null exception
- LINQ - get element within element
- LINQ operation with ternary operation causing tests to fail if logic is swapped
- How to get Data from parent child relationship Table using LINQ?
- Convert regex matches to the list of strings
- C # Linq equivalent of SQL nested group by
- How to ensure that there are 4 values added for each id
- How to compare minutes portion only of a TimeSpan in LINQ to Entities?
- The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties
- Unable to cast object of type System.Func`2 with Int64
- LINQy way to check if any objects in a collection have the same property value
- Weird behaviour with Linq