实体框架LINQ查询2个表

时间:2011-07-06 15:31:35

标签: linq entity-framework

我无法在Include("CITies")对象上使用db.Restaurants扩展方法。

当我使用include时出现以下错误:  DL.RESTAURANT does nto contain a definition for include or an extension method of include

namespace DL
{
    public class DLgetRestaurants
    {
        DL.FVRGDataContext db = new FVRGDataContext();

        public IEnumerable <RESTAURANT> getRestaurants(string cuisineName)
        {
           var restaurantList = 
               from RESTAURANT in db.RESTAURANTs.Include("CITies")
               where RESTAURANT.CITies.Any(t => t.CITY_ID == 2)
               orderby RESTAURANT.REST_NAME ascending
               select RESTAURANT;

            return restaurantList;
         }
     }
}

1 个答案:

答案 0 :(得分:0)

您只能使用包含在与另一个表有关系的实体上。除此之外,你不应该有问题。