none
Multiple connection for Entity Framework RRS feed

  • Question

  • Hi, I am new to Entity framework. The following is my codes:

    [Code]

    public partial class MainDBContext : DbContext
        {

            public MainDBContext()
                : base("name=MainDBContext")
            {
            }

            public MainDBContext(string conn)
                : base("name=" + conn)
            {
            }

            public virtual DbSet<Staff> Staff { get; set; }
        }

    In my codes, the Staff will retrieve data at the first time. However, when I change the MainDBContext connection, Staff won't retrieve data based on the new connection anymore. May I know what should I do? I need Staff retrieve data everytime the connection was changed.

    Wednesday, January 7, 2015 6:30 AM

Answers

  • Hello daniel,

    >>However, when I change the MainDBContext connection, Staff won't retrieve data based on the new connection anymore

    I am not sure how you change the connection, if you just make the connection connect to a new database, please make sure the Staff table in your new database contains rows, please check it.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, January 8, 2015 2:50 AM
    Moderator