Provider connection string from Entity Framework

前端 未结 1 1566
孤城傲影
孤城傲影 2020-12-09 16:31

If you are using object contex data model (with EDMX file), during its creation you might want to specify the connection string inside your config file.

The connect

相关标签:
1条回答
  • 2020-12-09 17:13

    Turns out there are two ways.

    I could parse the entity connection string via the EntityConnectionStringBuilder:

    string entityConnectionString = ConfigurationManager.ConnectionStrings["MyDbEntities"].ConnectionString;
    string providerConnectionString = new EntityConnectionStringBuilder(entityConnectionString).ProviderConnectionString;
    

    ...or if I have the specific model instance available, I can get it from here.

    ((System.Data.EntityClient.EntityConnection)ModelInstance.Connection).StoreConnection.ConnectionString;
    
    0 讨论(0)
提交回复
热议问题