Cannot convert lambda expression to type “string” because it is not a delegate type?

       var viewModel = new CoachIndexData();

        viewModel.Coaches = db.Coaches
            .Include(i => i.Courses.Select(c => c.Department))
            .OrderBy(i => i.LastName);

I Can not Understand how to do it. I am new in ASP.NET MVC


Taken from Cannot convert lambda expression to type 'string' because it is not a delegate type

This worked for me.

The Include() method with Entity Framework 4.1 has extension methods and it also accepts a lambda expression. So

context.CustomerSites.Include(c => c.Customer);

is perfectly valid, all you need to do is use this:

using System.Data.Entity;

Your issue lies on this line:

.Include(i => i.Courses.Select(c => c.Department))

The Include method, as described in the documentation, expects a string parameter not a lambda expression.

You need to provide Include with the path to "navigate" (i.e. how the navigation properties are set up on your context) to the required information. In your case I believe this would be:


Hope that helps.

I have Same Problem and I solved with following

using System.Linq.Dynamic;
using System.Linq;

code here..

public IPagedList<Inv_AMC> Gets(int? page, int? pageSize, string sort = "Id", string sortdir = "DESC", string searchKey = "")
            int pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
            int pageSizeValue = pageSize.HasValue ? Convert.ToInt32(pageSize) : 10;
            return dbSet.Where(x => (x.Customer.CustomerName.ToUpper().Contains(searchKey.ToUpper()) || searchKey == ""))
                  .OrderBy(sort + " " + sortdir)
                  .ToPagedList(pageIndex, pageSizeValue);

Where Inv_AMC and Customer is db object and references each other.

Need Your Help

can I do the following with php curl

php curl

what I'm trying to figure out if php's curl function is eligible to get in a password protected page, of course with given credentials, and curl a specified page?

Ad hoc distribution: failed to install app

ios iphone xcode5 provisioning-profile ad-hoc-distribution

I'm developing an ios app (only for iphone) and trying to have other people test it. I have no problem installing the app on my own device through Ad hoc distribution. When I tried installing on a...