Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 858
  • 838
  • 37.5k

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

May 16 2023 6:07 PM

Hello Team,

Am created repository for my Entity data and this the error I get when I run the 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.

CLASS

 public partial class tblCustomer
    {
        public int CustomerId { get; set; }
        public string CustomerName { get; set; }
    }

 

REPOSITORIES CLASS

namespace SmartRestaurantManagement.Repositories
{
    public class CustomerRepository
    {
         private readonly RestaurantDBEntities objRestaurantDBEntities;
        public CustomerRepository()
        {
            objRestaurantDBEntities = new RestaurantDBEntities();
        }

        public IEnumerable<SelectListItem> GetAllCustomer()
        {
            IEnumerable<SelectListItem> objSelectListItems = new List<SelectListItem>();
            objSelectListItems = (
                                    from obj in objRestaurantDBEntities.tblCustomers
                                    select new SelectListItem
                                  {
                                      Text = obj.CustomerName,
                                      Value = obj.CustomerId.ToString(),
                                      Selected = true
                                  }).ToList();
            return objSelectListItems;
        }
    }
}


Answers (3)