How to use Settings.settings for connection strings with entity infrastructure?

I would like to save the Entity model connection string in app.config using the same approach used by the old typed DataSet. Both use the same profile: <connectionStrings>.

Entity saves the connection as:

<add name="MyDB_Entities" connectionString="metadata=res://*/MyDB.csdl|res:......" providerName="System.Data.EntityClient" />

A typed DataSet saves as:

<add name="MyTest.Properties.Settings.MyDbString" connectionString="Data Source=.\sqlexpress;...." providerName="System.Data.SqlClient" />

The first has only accessibile, using the syntax "not typed", for example:

string s = ConfigurationManager.ConnectionStrings["MyDB_Entities"].ConnectionString;

The latter is “wrapped” by Settings.settings. Therefore you can write:

string s = Settings.Default.MyDbString;

The Entity element does not contain a namespace, so Settings.settings cannot parse it. Any idea / suggestion?

+3
source share

Source: https://habr.com/ru/post/1746521/


All Articles