Configure multiple database Entity Framework 6

后端 未结 3 600
予麋鹿
予麋鹿 2020-11-30 03:18

In my solution I have 2 projects that use Entity Framework 6. Each points to a different database, both using the same data provide - SQL Server. A third project in my solut

3条回答
  •  天命终不由人
    2020-11-30 03:48

    It's not important that how many DbContexts you have(In entity framework 6). Just put connection strings in appConfig or webConfig of startup project.

    Then you're ready to go.

    Example of appConfig with two connectionString with Ef 6.01 & Sql Compact 4.0

    
        

    And example of DbContexts:

    public class AppDb : DbContext
    {
        public AppDb()
            : base("MainDb")
        {
    
        }
    }
    
    public class AnotherDb : DbContext
    {
        public AnotherDb()
            : base("AnotherDb")
        {
    
        }
    }
    

    It's not important that your contexts are in separated projects or not, only Config of startup project is important.

    Let me know if any other information you need.

    Good luck

提交回复
热议问题