3

I was previously using the EF Power Tools which included an option to ReverseEngineerCodeFirst, and in the process of switching to EntityFramework Reverse POCO Generator.

Implementation:

        using (var db = new DbContext())
        {
            var user = db.Users
                .Include("MembershipType")
                .FirstOrDefault(u => u.UserName == userName);
            . . .
        }

In using the POCO generator, I now get an error on the .Include(...) line:

'System.Data.Entity.IDbSet' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Data.Entity.IDbSet' could be found (are you missing a using directive or an assembly reference?)

In the generated context (and IContext):

    DbSet<User> Users { get; set; } // Users

In the context tt template, I changed instances of IDbSet to DbSet which fixed the issue, but I'm curious as to why, if IDbSet is an interface for DbSet, why doesn't IDbSet work?

ElHaix
  • 12,846
  • 27
  • 115
  • 203
  • I have plans to remove IDbSet from the generator and use DbSet instead. See http://efreversepoco.codeplex.com/workitem/89 – Simon Hughes Apr 14 '15 at 14:28
  • I now use DbSet and have removed the use of the interface IDbSet from the generator. So you should be able to use your original `.Include` code. – Simon Hughes Sep 24 '15 at 10:34

4 Answers4

1

I think that maybe you are just missing the using System.Data.Entity; statement.

Lars
  • 65
  • 2
  • 8
1

IDbSet is a deprecated interface by Microsoft. The generator now uses DbSet instead.

Update to the latest EF Reverse POCO Generator here.

Source code is here.

Simon Hughes
  • 3,534
  • 3
  • 24
  • 45
0

The error says it all:

System.Data.Entity.IDbSet' does not contain a definition for 'Include' and no extension method...

The interface just doesn't have the method. I'm not sure why these method are not part of the interface. Maybe because IDbSet was introduced to facilitate mocking, and Include is a method that's very hard to mock.

Instead, you can use one of the the Include extension methods in the namespace System.Data.Entity. These method are defined on IQueryable(<T>), which is an interface that IDbSet implements.

The same is true for another important method that's not in the IDbSet interface: AsNoTracking. (Also hard to mock - in a sense - because tracking is hard to mock).

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
0

I solved the exact same problem reinstalling the Entity Framework.

Update-Package EntityFramework -Reinstall

The problem was the missing reference to EntityFramework.dll.

Douglas Gandini
  • 827
  • 10
  • 24