I am trying to map various markers on google map with a info window. It is all working fine till I try to pass a string through the controller.
I get the error below:
"LINQ to Entities does not recognize the method 'System.String GetMainPhoto(Int32)' method, and this method cannot be translated into a store expression."
I have read this is mainly caused because ToString method or some other methods are not valid to use. But, I am not really sure how to correct this error in this case.
Basically, I have a db - PropertyPhoto that holds the filename of the pictures. GetMainPhoto basically looks up all the rows and returns the main pic file name.
public string GetMainPhoto(int id)
        {
            return db.PropertyPhotos.Single(p => p.PropertyId == id && p.MainPic == true).PhotoLocation;
        }
Controller is as follows:
public ActionResult Map()
        {
            if (Request.IsAjaxRequest())
            {
                var properties = websiteRepository.FindAllProperties();
                var jsonProperties = from property in properties
                                     select new JsonProperty
                                     {
                                         PropertyId = property.PropertyId,
                                         NoOfBedroom = property.NoOfBedrooms,
                                         Price = property.Price,
                                         Address1 = property.PropertyAddress.Address1,
                                         MainPicSrc = websiteRepository.GetMainPhoto(property.PropertyId),
                                         Latitude = property.PropertyAddress.Latitude,
                                         Longitude = property.PropertyAddress.Longitude
                                     };
                return Json(jsonProperties.ToList(), JsonRequestBehavior.AllowGet);
            }
            else 
            {
                return View();
            }
        }
 
     
     
    