开发者

How to use Settings.settings for entity framework connection strings?

I'd like to store the Entity model connection string in the app.config using the same approach used by old Typed DataSet. Both use the same section: <connectionStrings>.

Entity saves the connection as:

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

Typed DataSet saves as:

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

The former is only accessibile using a "not-typed" syntax, like:

string s开发者_运维问答 = ConfigurationManager.ConnectionStrings["MyDB_Entities"].ConnectionString;

The latter is "wrapped" by Settings.settings. So you can write:

string s = Settings.Default.MyDbString;

The Entity entry does not contain the namespace so Settings.settings is not able to parse it. Any idea /suggestion?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜