Susan
Susan

Reputation: 1832

LINQ to Entities: can't convert Lambda expression to type "string"

My lambda expressions within the Include statements are getting the error in that I've included in the title of this post. I do have a 'using.System.Linq' in my class. What's up? ~susan~

FVTCEntities db = new FVTCEntities();

public List<RESTAURANT> getRestaurants(string cuisineName)
{
    var cuisineID = db.CUISINEs.First(s => s.CUISINE_NAME == cuisineName).CUISINE_ID;

    List<RESTAURANT> result = (from RESTAURANT in db.RESTAURANTs.Include(x => x.CITY).Include(x => x.CUISINE) 
                               where RESTAURANT.CUISINE_ID == cuisineID 
                               select RESTAURANT).ToList();

     return result;
}

Upvotes: 0

Views: 1629

Answers (3)

J.W.
J.W.

Reputation: 18181

Are you using DBContext in EF4.1, based on the blog post by the ET team, Include is an extension method in the System.Data.Entity namespace so make sure you are using that namespace.

Upvotes: 4

Manu
Manu

Reputation: 29143

In EF, the Include() method accepts a string as parameter. If you want it to accept Lambda Expressions, you should read the following post: http://tomlev2.wordpress.com/2010/10/03/entity-framework-using-include-with-lambda-expressions/

Upvotes: 0

Ryan Bennett
Ryan Bennett

Reputation: 3432

http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx

I don't have a ton of experience with .Include(), but this seems to make sense.

maybe .Include("CITY").Include("CUISINE")

Upvotes: 0

Related Questions