Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 753
  • 1.2k
  • 58.2k

LINQ to Entities does not recognize the method 'System.String ToString

Jul 20 2023 12:04 PM

Hello Team,

Please am getting the below error from my controller, kindly assist me

Additional information: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

public ActionResult Index()
{
    RoomViewModel objRoomViewModel = new RoomViewModel();
    objRoomViewModel.ListOfBookingStatus = (from obj in objHotelDbEntities.BookingStatus
                                            select new SelectListItem()
                                             {
                                                 Text = obj.BookingStatus,
                                                 Value = obj.BookingStatusId.ToString(),
                                                 Selected = false
                                             }).ToList();
    objRoomViewModel.ListOfRoomRtype = (from obj in objHotelDbEntities.RoomTypes
                                        select new SelectListItem()
                                        {
                                            Text = obj.RoomTypeName,
                                            Value = obj.RoomTypeId.ToString(),
                                            Selected = false
                                        }).ToList();

    return View(objRoomViewModel);
}

 


Answers (2)