Ladislav Mrnka advises using Include

I am trying to use the Ladislav Mrnka tip 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 message. The compiler does not 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 ADO.NET Entity Framework 4.1 from here .

+5
source share
1 answer

Two things:

1) You need a link (s using) to System.Data.Entitywhere it is defined Include:

using System.Data.Entity;

2) Your class must be marked publicand static, otherwise, you cannot insert an extension method into it:

public static class Extensions
{ 

Edit:

EntityFramework - , EntityFramework.

Nuget:

1.) (View | Other Windows | Package    )

2.) Install-Package EntityFramework

+6

All Articles