5

I am trying to use Ladislav Mrnka's advice here to use:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Data.Entity;

namespace SimTask.Data.EF4
{
    public static class Extensions
    {
        public static IQueryable<T> IncludeMultiple<T>(this IQueryable<T> query,
            params Expression<Func<T, object>>[] includes)
            where T : class
        {
            if (includes != null)
            {
                query = includes.Aggregate(query,
                          (current, include) => current.Include(include));
            }

            return query;
        }

    }
}

But I get an error. The compiler doesn't recognize current.Include:

Error   7   'System.Linq.IQueryable<T>' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Linq.IQueryable<T>' could be found (are you missing a using directive or an assembly reference?)   C:\MySolution\MyProj.Data.EF4\Extensions.cs 19  57  MyProj.Data.EF4

I installed the ADO.NET Entity Framework 4.1 from here.

Community
  • 1
  • 1
Naor
  • 23,465
  • 48
  • 152
  • 268

1 Answers1

6

Two things:

1) You need a reference (and using) to System.Data.Entity, that is where Include is defined:

using System.Data.Entity;

2) Your class should be marked public and static, otherwise you cant put an extension method in it:

public static class Extensions
{ 

Edit:

You also need to include EntityFramework in your project - if you expand references in your project you should see EntityFramework.

The easiest way to add it is via Nuget:

1.) Open the Package Manager Console (View | Other Windows | Package Manager Console)

2.) Type Install-Package EntityFramework

BrokenGlass
  • 158,293
  • 28
  • 286
  • 335
  • @Naor: Did you add a reference to EntityFramework to your project? – BrokenGlass Apr 23 '11 at 16:33
  • I have reference to System.Data.Entity. Doesn't it represents the entity framework? – Naor Apr 23 '11 at 16:33
  • 2
    @Naor: It represents EFv4. EFv4.1 are additional features to EFv4. You must reference both System.Data.Entity.dll and EntityFramework.dll (you will find it in installation directory of EFv4.1) – Ladislav Mrnka Apr 23 '11 at 16:36