0

I was checking ScottGu video where he introduces the DBContext, which looks interesting but it seems that in order to generalize the concept you have to always declare manually the tables that want to become accessible through the DBContext class.

Mainly if I understood correctly from his video, you have to declare a class that inherits from DbContext, something like this:

public class MyDB: DbContext
{
    public DbSet<User> Users { get; set; }
}

My question is: do I really have to manually add every entity? And what if I import Stored Procedures? What do I declare on my newly created MyDB class??

What's the right way to do this if you already have stored procedures that you want to use ??

SF Developer
  • 5,244
  • 14
  • 60
  • 106

1 Answers1

0

There are two approach in using of DbContext. First is database first which I think that you can use store Procedures, second is Code First, that Code First currently only supports mapping to tables. This unfortunately means that you can’t map Code First directly to stored procedures, views, or other database objects. If you are letting Code First generate a database, there is no way to create these artifacts in the database, other than manually adding them once Code First has created the database. If you are mapping to an existing database, there are some techniques you can use to get data from non-table database artifacts

Elvin Mammadov
  • 25,329
  • 11
  • 40
  • 82
  • Right so then my next question would be this...http://stackoverflow.com/questions/16977595/entity-framework-is-using-stored-procedure-such-a-bad-idea ?? – SF Developer Jun 07 '13 at 06:25