(This was a two-part question, but since the second part is literally important, I decided to split it into two separate posts. See Using Serialization to copy objects between two object-oriented objects in the Entity Framework for the second part.
I want to create a fairly general database cloner for my entity model. In addition, I may need the support of various suppliers, etc. I am using the API ObjectContext.
I already know this question and the example documentation of EntityConnectionStringBuilder MDSN , but I need to know if there is a programmatic way to get the values to initialize the properties Providerand Metadatafor EntityConnectionStringBuilder?
using (var sourceContext = new EntityContext()) {
var sourceConnection = (EntityConnection) sourceContext.Connection;
var targetConnectionBuilder = new EntityConnectionStringBuilder();
targetConnectionBuilder.ProviderConnectionString = GetTargetConnectionString();
targetConnectionBuilder.Provider = "System.Data.SqlClient";
targetConnectionBuilder.Metadata = "res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl";
using (var targetContext = new EntityContext(targetConnectionBuilder.ConnectionString)) {
if (!targetContext.DatabaseExists())
targetContext.CreateDatabase();
}
}
That is, there is a way to get
"System.Data.SqlClient""res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl"
from somewhere and not use literal values?
source
share