I am trying to add datetime in Linq query.
Error is : LINQ to Entities does not recognize the method 'System.DateTime AddMinutes(Double)' method, and this method cannot be translated into a store expression.
It is working in Link to SQL but not working to LINQ to Entity.
Is there any another way to do this.
Thanks
DataClassesDataContext datacontext = new DataClassesDataContext();
int concertid = Convert.ToInt32(ddlConcerts.SelectedValue.ToString());
GridView1.DataSource = (from ticketallocation in datacontext.tblConcertTicketAllocation
where ticketallocation.ConcertID == concertid
&& ticketallocation.Section == ddlSection.SelectedValue
&& ticketallocation.Row == ddlRows.SelectedValue
select new
{
AutoID = ticketallocation.AutoID,
ConcertID = ticketallocation.ConcertID,
Section = ticketallocation.Section,
Row = ticketallocation.Row,
Seats = ticketallocation.Seats,
Status = ticketallocation.Status == 3 ? "<span style=\"color:#FF0000;\">Sold</span>" :
ticketallocation.Status == 2 ? "<span style=\"color:#999999;\">Aisle Break</span>" :
ticketallocation.Status == 0 ? "<span style=\"color:#009900;\">Available</span>" :
ticketallocation.Status == 1 && ticketallocation.DateandTime.Value.AddMinutes(16) > DateTime.Now ? "<span style=\"color:#FF9900;\">Looking</span>" : "<span style=\"color:#009900;\">Available</span>",
DateandTime = ticketallocation.DateandTime,
OrderNumber = ticketallocation.OrderNumber
}).ToList();
GridView1.DataBind();
In EntityFramework 6 EntityFunctions are gone.
Use
System.Data.Entity.DbFunctions
instead
This isn't answer to the OP question, but maybe it helps to some incoming viewers.
If you are using Entity Framework v4, try this code
System.Data.Objects.EntityFunctions.AddMinutes(ticketallocation.DateandTime.Value, 16)
instead of
ticketallocation.DateandTime.Value.AddMinutes(16)
If you are using Entity Framework v1, the solution is Entity SQL Canonical Functions, e.g., like it is described in this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With