DBContext vs ObjectContext - using stored procedures

I watched a ScottGu video where it introduces a DBContext that looks interesting, but it seems that to summarize the concept, you should always manually declare tables that want to be accessible through the DBContext class.

Basically, if I understood his video correctly, you need 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 need to manually add all entities? So what if I import stored procedures ? What am I declaring in my newly created MyDB class?

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

0
source share
1 answer

There are two approaches to using DbContext. First, the first database, and I think you can use the repository procedures, secondly, Code First, which Code First currently only supports table matching. Unfortunately, this means that you cannot convert First code directly to stored procedures, views, or other database objects. If you allow Code First to generate a database, there is no way to create these artifacts in the database, except to manually add them once Code First has created the database. If you are attaching to an existing database, there are some methods that you can use to retrieve data from database artifacts other than a table.

0
source

Source: https://habr.com/ru/post/1484978/


All Articles