Regular expression for remove metadata

為{幸葍}努か 提交于 2019-12-12 10:46:09

问题


I trying to create a application with use some Entity Framework and some old DataSets but I only have a dynamic connection string using entity and need remove metadata at runtime to create a connection string to my database. Anyone know a way to remove all metadata from Entity Framework Connection

I have this

metadata=res://*/Models.SiteModel.csdl|res://*/Models.SiteModel.ssdl|res://*/Models.SiteModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=(local);Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=P@ssw0rd;MultipleActiveResultSets=True"

and need only this:

Data Source=(local);Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=P@ssw0rd;MultipleActiveResultSets=True

回答1:


You can use the EntityConnectionStringBuilder class:

string connectionString = "metadata=res://*/Models.SiteModel.csdl|res://*/Models.SiteModel.ssdl|res://*/Models.SiteModel.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source=(local);Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=P@ssw0rd;MultipleActiveResultSets=True\"";
EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(connectionString);
builder.Metadata = null;
connectionString = builder.ConnectionString;



回答2:


A better property to use is builder.ProviderConnectionString rather than stripping the Metadata from the builder to get build.ConnectiongString.



来源:https://stackoverflow.com/questions/6030430/regular-expression-for-remove-metadata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!