Linq-to-Entities Include method not found

前端 未结 5 1921
时光取名叫无心
时光取名叫无心 2020-12-16 10:31

I am using EF4 within a MVC3 application and I was looking for a way to view all my contacts within a given workgroup. In the controller I specified:

var wg          


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 11:33

    Yes the method is build into EF but it is not available on IQueryable interface. It is available on ObjectQuery. If you want to call it on IQueryable you must create your own extension wich will convert current query to ObjectQuery and perform Include. Something like:

    public static IQueryable Include(this IQueryable query, string property)
    {
      var objectQuery = query as ObjectQuery;
      if (objectQuery == null)
      {
        throw new NotSupportedException("Include can be called only on ObjectQuery");
      }
    
      return objectQuery.Include(property);
    }
    

    Or you must use Entity Framework Feature CTP5 where such extensions are already available.

提交回复
热议问题