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: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)
score:1
You can use SqlFunction Class:
.Where(x => SqlFunctions.DateAdd("month",x.Commitments.Value,x.JoiningDate).Month == ToDate.Value.Month)
Source: stackoverflow.com
Related Articles
- How to add Month in date time and Compare with another date time in Linq?
- Entity Framework: Linq where clause compare date and time value with seconds difference
- how to combine two columns Date and Time and compare it with given DateTime using linq
- Use Linq query to compare date only with DateTime field
- 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?
- c# find item in list returned by LINQ query and compare its value with another item in list
- Accessing SQL Server time in code with LINQ
- 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
- Grouping data by timestamp date and time with linq
- Linq Query Where() with Date subtraction taking excessive time
- C# + Deedle: Creating a Data Series with Continuous DateTime Keys from Another with Date Gaps using LINQ
- Linq select time with date + 1
- how to query a record with latest date as part of another linq query
- Display data in sorting order based on arrived time with current date using LINQ query
- What ways exist with linq to compare if a case insensitive and culture using string exists within another
- How to select only the records with the highest date in LINQ
- LINQ to SQL: GroupBy() and Max() to get the object with latest date
- how to use entity framework to group by date not date with time
- Linq to update a collection with values from another collection?
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- Linq To Sql compare Time only
- Getting object with max date time value in one of it's properties
- How to get the latest date inserted from the table with Linq to entities
- Find overlapping time periods (events) with LINQ
- Compare only time from datetime in entity framework 6 with odp.net Oracle 12c
- LINQ TO SQL, Dynamic query with DATE type fields
- C# Linq string compare with indexOf
- Compare only Date in nHibernate Linq on a DateTime value
- Quickly joining 2 list without duplicates
- LINQ ordering by a child value
- How to convert XElement to lowercase?
- Help with recursive linq expression
- select distinct xelement based on attribute
- How to convert a String[] to an IDictionary<String, String>?
- How to use linq extensions methods using Expression.Call
- Flattened records to parent/child objects using LINQ. Without duplication of data
- Linq updates extra rows
- Can we do Parallel EF LINQ Queries?
- How to build object hierarchy for serialization with json.net?
- how can I 'walk' the relationships between tables in LINQ?
- Removing values from a generic list
- Create a ASP.net login system based on a existing table?
- Using Linq and the Trim.Text for Search
- Linq Expression tree compiling non-trivial object constants and somehow referring to them
- C# getting sorted list of images
- How to find if an element of a list is in another list?
- Linq Table select where IN IQueryable
- Linq query may be null property is not