whoah
whoah

Reputation: 4443

how to add new model in exist database

How can I add new model MVC in proper way? I have one model with UsersContext. I want to create another - NewContext.

Is the code below will work without any problems? And maybe there is a better solution to create model in existing database? What exacly mean UsersContext and NewContext in code?

public class NewContext : DbContext
{
    public NewContext ()
        : base("DefaultConnection")
    {
    }

    public DbSet<test1> test1{ get; set; }
    public DbSet<test2> test2{ get; set; }
    public DbSet<test3> test3{ get; set; }

}
  (...)

Upvotes: 1

Views: 110

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

Is the code below will work without any problems?

Yes, this will work. The DbContext is used to group the entities you want to work with in your application. In fact you do not need a second context. You could have only one DbContext in which you add all your domain entities as DbSet<T> properties and then work with this context.

Upvotes: 3

Related Questions