Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for remove metadata

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
like image 707
pedrofernandes Avatar asked May 17 '11 11:05

pedrofernandes


1 Answers

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;
like image 188
Thomas Levesque Avatar answered Sep 19 '22 01:09

Thomas Levesque