Share via


MVC The specified type member 'FullName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

Question

Friday, March 18, 2016 6:24 PM

Hello 

I am trying to implement a search on another controller and am coming across the following error. 

The specified type member 'FullName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

I have been following the following tutorial http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application   and have implemented this on my customers controller. I now need to implement this on another controller i.e my suppliers. This is because the supplier might have a significant number of customers assigned to them.

What I have done is the following in my controller

    // GET: Plans
        public ActionResult Index(string search, string sort)
        {
            ViewBag.NameSortParam = String.IsNullOrEmpty(sort) ? "name_desc" : "";
            var supplier = from p in db.suppliers
                      select p;

            if (!String.IsNullOrEmpty(search))
            {
                //uses the customer variable and then matches it to the search string
                supplier = supplier.Where(c => c.Customer.FullName.Contains(search));
            }
            switch (sort)
            {

                case "name_desc":
                    supplier = plans.OrderByDescending(s => s.Customer.FullName);
                    break;
                default:
                    supplier = plans.OrderBy(s => s.Customer.FullName);
                    break;
            }

            // var plans = db.Plans.Include(p => p.Agreement).Include(p => p.Customer);
            // return View(plans.ToList());

            return View(supplier );
        }

Pretty sure it's to do with my LINQ query and think I might need a join. Not sure how though 

If anybody could help would be great 

Many thanks

Mark

All replies (2)

Monday, March 21, 2016 9:57 AM âś…Answered

Hi Mark,

            switch (sort)
            {

                case "name_desc":
                    supplier = plans.OrderByDescending(s => s.Customer.FullName);
                    break;
                default:
                    supplier = plans.OrderBy(s => s.Customer.FullName);
                    break;
            }

From your code, it seems that you want sort the supplier, if that it is the case, please check the above code, and modify it as below:

            switch (sort)
            {

                case "name_desc":
                    supplier = supplier.OrderByDescending(s => s.Customer.FullName);
                    break;
                default:
                    supplier = supplier.OrderBy(s => s.Customer.FullName);
                    break;
            }

Best regards,
Dillion


Friday, March 18, 2016 6:50 PM

Hi,

On which line does it happen? How is declared FullName? Not sure also to get how Supplier and Customer are related one to the other (you have a single Customer for a Supplier ???)

 "plans" seems to come from nowhere (if it happens there, shouldn't this be deleted or commented for now ?)