Passing Connection String to Entity Framework 6

前端 未结 5 473
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 08:07

I am using EF6 in a class library (database first)

When I followed the wizard and added my tables I selected not to store the connections string in the app.config an

5条回答
  •  忘掉有多难
    2020-12-14 08:36

    I have used the connection string like this, entity connection string instead of normal connection string

      SqlConnectionStringBuilder sqlString = new SqlConnectionStringBuilder()
            {
        DataSource = "SOURAV-PC", // Server name
        InitialCatalog = "efDB",  //Database
                UserID = "sourav",         //Username
                Password = "mypassword",  //Password
            };
            //Build an Entity Framework connection string
    
            EntityConnectionStringBuilder entityString = new EntityConnectionStringBuilder()
            {
                Provider = "System.Data.SqlClient",
                Metadata =   "res://*/testModel.csdl|res://*/testModel.ssdl|res://*/testModel.msl",
                ProviderConnectionString = sqlString.ToString()
            };
            return entityString.ConnectionString;
        }
    

提交回复
热议问题