3

I am trying stuff out on MVC4 Beta. Project is in VS11, EF 5.0-Beta, using Code First approach. Created simple Model poco and DbContext derived class with single IDbSet<> property for model class. Connection string with LocalDb.

I noticed when context's Entity Set property is type of IDbSet<> then I get message from VS when I try to create new controller with “Controller with read/write actions and views, using Entity Framework” Scaffolding template: "There was an error generating 'MyProject.MyNamespace.MyContext'. Try rebuilding your project." Even Clean Solution and building again doesn’t help.

If I changed Entity Set property to type DbSet<> then controller scaffolding succeeds. Is it a bug or is it expectable?

Br, Lauri

tereško
  • 58,060
  • 25
  • 98
  • 150
Lauri Saar
  • 63
  • 1
  • 5

1 Answers1

-1

It is not a bug you cant instantiate an instance of an Interface. The I in front of IDbSet denotes the type as an interface (By convention). So you were trying to create an instance of that interface. Instead you need to delcare it with DBSet<> which is an implementation of the IDBSet<> interface. I hope this clarifies your issue.

Kevin
  • 127
  • 1
  • 7
  • OK, but after scaffolding with DbSet<> properties I can change them to IDbSet<> and application builds and works. Is it result of .Net type resolving or something in that nature? – Lauri Saar Mar 24 '12 at 11:03
  • The correct syntax is to use DbSet<> and not IDbBSet<> as far as i know – Kevin May 02 '12 at 23:55