smita pinky

smita pinky

  • 2.2k
  • 13
  • 1.7k

How many datacontext will be there in Project

Jul 12 2021 6:15 AM

I am new to mvc. I would like to use EF code first approach.I need 3 different database in my project. What I understood from internet till yet

1: That means need to create 3 diff connectionstring in my config file.Appropriate 3 diff context class will be there (project).If context class and connectionstring name is different,need to mention in it's constructor with the help of base keyword. Each context class have proprties as all table of that database.When I build the project, context class will create database with name mention in connectionstring along with all dbcontext property in that database as table if not already exist.

2: If I want to add new table in my database,here I am using EF code first approach So I need to create a class for that and mention it in it's appropriate dbcontext class only and build project. Enable migration Add Migration Update database

This will add table to my database and migration file in project which has up and down method.

Is this a right approach to do.I want to update only perticular databse not all. Shall I write name of database while migrating

Answers (3)