Error in method Include LinQ: Unable to load type 'System.Data.Entity.DbExtensions'

2

I have an application of WindowsAplication in C # , it is developed in N-Layers . The method in the data layer to get a table did not give problems:

public List<styh_m_005_cultivo> GetAll()
{
    using (var context = new TermometroDbContext())
    {
        return (
            from entity in context.styh_m_005_cultivo
            select entity
        ).ToList();
    }
}

But when adding method include :

public List<styh_m_005_cultivo> GetAll()
{
    using (var context = new TermometroDbContext())
    {
        return (
            from entity in context.styh_m_005_cultivo
            select entity
        ).Include(c => c.styh_m_006_agricultor)
         .Include(c => c.styh_p_004_recinto).ToList();
    }
}

A System.TypeLoadException occurs:

  

Unable to load type System.Data.Entity.DbExtensions of assembly EntityFramework , Version=6.0.0.0 , Culture=neutral , PublicKeyToken=b77a5c561934e089 .

    
asked by Andy 24.03.2017 в 17:40
source

1 answer

1

It is a version conflict between EF 5.0 and EF 6.0, it eliminates the reference to the assembly System.Data.Entity and rebuilds it for Entity Framework 6.0 (regenerates it with NuGet), it also deletes any line like this:

Using System.Data.Entity.DbExtensions;

since that namespace changed from EF 5.0 to EF 6.0.

    
answered by 24.03.2017 / 18:03
source