DateTime Add a calculation inside Linq to query objects

I am trying to add datetime to a Linq query.

Error: LINQ to Entities does not recognize the Method Method.DateTime AddMinutes (Double) 'method, and this method cannot be translated into a storage expression.

It works in Link to SQL, but does not work with LINQ to Entity.

Is there any other way to do this.

thank

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();
+5
source share
3 answers

In EntityFramework 6 EntityFunctions gone.

Using

System.Data.Entity.DbFunctions

instead

This is not an answer to an OP question, but perhaps it helps some inbound viewers.

+10
source

If you are using Entity Framework v4, try this code

System.Data.Objects.EntityFunctions.AddMinutes(ticketallocation.DateandTime.Value, 16) 

instead

ticketallocation.DateandTime.Value.AddMinutes(16)

Entity Framework v1, Entity SQL Canonical Functions, , .

+8

You can use: System.Data.Entity.DbFunctions

0
source

All Articles