Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In my controller i am trying to use include with EF4 to select related entities, but the lambda expression is throwing the following error,

i have the related entity defined in the Entity class like

public class CustomerSite
{
    public int CustomerSiteId { get; set; }
    public int CustomerId { get; set; }
    public virtual Customer Customer { get; set; }
}

Then in my controller i have

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

 public ViewResult List()
 {
    var sites = context.CustomerSites.Include(c => c.Customer);
    return View(sites.ToList());
 }

Can anyone kindly point me in the right direction on what i'm doing wrong here?

like image 725
Liam Avatar asked Jul 14 '11 16:07

Liam


2 Answers

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;
like image 128
amarnath chatterjee Avatar answered Sep 18 '22 06:09

amarnath chatterjee


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.

like image 37
Will Avatar answered Sep 22 '22 06:09

Will