none
Problem with EF Query - Advice on how to rewrite required. RRS feed

  • Question

  • Hi

    Below is the simple query that was written in linq-to-sql days, now i am using EntityFramework and it gives error that ToString() cannot be used in this query.   ""LINQ to Entities does not recognize the method 'System.String ToString()"......"

    Please advice how should i rewrite this query.

      var result1 = from x in db.RM
                          where (from y in db.AT
                                 where y.FK_UserID == Page.User.Identity.Name
                                 select y.FK_RunID).Contains(x.RunID)
                          ||
                          x.CreatedBy == Page.User.Identity.Name
                          orderby x.CreatedDate descending
                          select new
                          {
                              x.RunID,
                              x.IsDeleted,
                              RunStatus = (
                              x.RunStatus == (int)RunStatus.NotStarted ? RunStatus.NotStarted.ToString() :
                              x.RunStatus == (int)RunStatus.Running ? (RunStatus.Running.ToString()) :
                              x.RunStatus == (int)RunStatus.WaitingForClients ? (RunStatus.WaitingForClients.ToString()) :
                              x.RunStatus == (int)RunStatus.CompletedWithSuccess ? (RunStatus.CompletedWithSuccess.ToString()) :
                              x.RunStatus == (int)RunStatus.CompletedWithFailed ? (RunStatus.CompletedWithFailed.ToString()) :
                              x.RunStatus == (int)RunStatus.Aborted ? (RunStatus.Aborted.ToString()) :
                              x.RunStatus == (int)RunStatus.Canceled ? (RunStatus.Canceled.ToString()) :
                              "Unknown"
                              )
                          };

    Monday, April 22, 2013 2:49 PM

Answers

All replies