0
好吧,而不是與xml
戰鬥,我被引導到EntityConnectionStringBuilder
。所以這是我迄今爲止所擁有的。 EnityManagerFactory
調用創建方法。現在Create方法創建並返回一個EntityManager
,在這種情況下稱爲UnionEntities
。使用EntityConnectionStringBuilder建立一個動態的IdeaBlade連接字符串
public UnionEntities Create()
{
string providerName = "System.Data.SqlClient";
string serverName = ConfigurationManager.AppSettings["DatabaseServer"];
string databaseName = ConfigurationManager.AppSettings["DatabaseName"];
string userName = ConfigurationManager.AppSettings["DatabaseUserName"];
string password = ConfigurationManager.AppSettings["DatabasePassword"];
bool integratedSecurity = bool.Parse(ConfigurationManager.AppSettings["IntegratedSecurity"]);
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
// Set the properties for the data source.
sqlBuilder.DataSource = serverName;
sqlBuilder.InitialCatalog = databaseName;
sqlBuilder.IntegratedSecurity = integratedSecurity;
sqlBuilder.UserID = userName;
sqlBuilder.Password = password;
// Build the SqlConnection connection string.
string providerString = sqlBuilder.ToString();
// Initialize the EntityConnectionStringBuilder.
EntityConnectionStringBuilder entityBuilder =
new EntityConnectionStringBuilder();
//Set the provider name.
entityBuilder.Provider = providerName;
// Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString;
// Set the Metadata location.
entityBuilder.Metadata = @"res://*/UnionModel.csdl|
res://*/UnionModel.ssdl|
res://*/UnionModel.msl";
var manager = new UnionEntities();
manager.Saving += SaveValidationHelper.SavingHandler;
manager.DefaultQueryStrategy = QueryStrategy.DataSourceOnly;
return manager;
}
現在常新UnionEntities()
使用在app.Config file
的ConnectionString
。我現在如何告訴它使用我的EntityConnectionStringBuilder
對象?