Using entity framework on multiple databases

后端 未结 2 1517
悲&欢浪女
悲&欢浪女 2020-12-01 04:23

I am writing a payroll system that will integrate with a pre-existing system. The original system had a master database that handled user management and some global configur

2条回答
  •  無奈伤痛
    2020-12-01 05:07

    It is very simple. I have:

    public WMSEntities() : base("name=WMSEntities") //WMSEntities is conection string name in     web.config also the name of Entitiframework
    {
    }
    

    already in autogenerated Model.Context.cs of edmx folder

    To connect to multiple database in runtime, I created another constructor that takes connection string as parameter like below in same file Model.Context.cs

    public WMSEntities(string connStringName)
        : base("name=" + connStringName)
    {
    }
    

    Now I added other connection string in Web.Config for example

    
                                                            
提交回复
热议问题