-1

I want to retrieve a date from a database. I am using this LINQ query: this is my whole controller

[HttpGet]
public ActionResult FillSettlementDate(string Tenor1)
{
    DateTime issueDate = Convert.ToDateTime(Session["IssueDate1"]);
    int aucid = Convert.ToInt32(Session["auctionid"]);
    string products=  Convert.ToString(Session["Product_Id"]);
    var SettleDate =  db.AUCDATA_TENORS
        .Where(c => c.TENOR_ID == Tenor1 && c.ISSUE_DATE == issueDate && c.AUCTION_ID ==aucid  && c.PRODUCT_ID ==products)
        .Select(c => c.SETTLE_DATE).ToList();
    return Json(SettleDate, JsonRequestBehavior.AllowGet);
}

it is giving me Not Supported Exception

An exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

I want to retrieve this date and pass it in JSON

return Json(SettleDate, JsonRequestBehavior.AllowGet);
Mussaib Siddiqui
  • 199
  • 2
  • 15
  • 1
    You have said retrieve **a** date, but you query returns a collection (not a single date). No where in the code have you used `.ToString()` so the error is not related to what you have shown. –  Jul 18 '16 at 08:18
  • @StephenMuecke well, maybe the `issueDate` variable is a string, so maybe to compare `c.ISSUE_DATE == issueDate` it is trying internally to convert the ISSUE_DATE to a string. We definitely need more information. – Charlie Jul 18 '16 at 08:20
  • 1
    @CarlosAlejo in that case it would not compile with the error "can't compare a DateTime with a string" – fubo Jul 18 '16 at 08:22
  • @StephenMuecke Sir actually i am converting issue date above this query DateTime issueDate = Convert.ToDateTime(Session["IssueDate1"]); int aucid = Convert.ToInt32(Session["auctionid"]); string products= Convert.ToString(Session["Product_Id"]); – Mussaib Siddiqui Jul 18 '16 at 09:13
  • Edit your question with the relevant code (not in comments) –  Jul 18 '16 at 09:16
  • @StephenMuecke i have updated my question plz check where i am wrong – Mussaib Siddiqui Jul 18 '16 at 09:17
  • That code will still not throw that exception. Is that the complete code in the method? –  Jul 18 '16 at 09:20
  • Possible duplicate of [LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression](http://stackoverflow.com/questions/5899683/linq-to-entities-does-not-recognize-the-method-system-string-tostring-method) – Clint Jul 18 '16 at 09:28
  • Thankyou Sir i Problem Solved.. – Mussaib Siddiqui Jul 18 '16 at 09:31

1 Answers1

0

Try Select(c => c.SETTLE_DATE.ToString()) instead of Select(c => c.SETTLE_DATE) .

Dexion
  • 1,101
  • 8
  • 14