开发者

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

开发者 https://www.devze.com 2023-03-20 15:19 出处:网络
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~

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) 
                               wh开发者_如何学编程ere RESTAURANT.CUISINE_ID == cuisineID 
                               select RESTAURANT).ToList();

     return result;
}


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.


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/


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")

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号