Cannot convert lambda expression to type 'string' because it is not a delegate type
Well, the post is quite old, but just replying here to update it. Well, 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;
Include is an extension method in the System.Data.Entity namespace, you need to add:
using System.Data.Entity;
Then you can use the lambda expression, instead of the string.
The Include
method expects a string, not a lambda:
public ViewResult List()
{
var sites = context.CustomerSites.Include("Customer");
return View(sites.ToList());
}
Of course you could write a custom extension method which would work with lambda expressions and make your code independant of some magic strings and refactor friendlier.
But whatever you do PLEASE OH PLEASE don't pass EF autogenerated objects to your views. USE VIEW MODELS.