EntityConnectionStringBuilder

In my last Metadata post I suggested using a string template to create an EntityConnection connection string. Well it turns out there is a better way...

Enter the EntityConnectionStringBuilder class. The only thing it is missing is the ability to specify the location of each of the metadata files (CSDL, SSDL and MSL) separately, you still have to do add them in one go in a pipe delimited string:

EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder();
builder.Metadata = string.Format("{0}|{1}|{2}", csdlPath, ssdlPath, mslPath);
builder.Provider = "System.Data.SqlClient";
builder.ProviderConnectionString = sqlConnectionString;

EntityConnection connection = new EntityConnection(builder.ConnectionString);

Ah... that's better.