我决定将Entity Connection String
从app.config
移到代码中。但是在设置完成之后:
public static string GetConnectionString() {
string connection = "";
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
sqlBuilder.DataSource = dbServer;
sqlBuilder.InitialCatalog = dbInitialCatalog;
sqlBuilder.IntegratedSecurity = false;
sqlBuilder.UserID = dbUserName;
sqlBuilder.Password = dbPasswWord;
sqlBuilder.MultipleActiveResultSets = true;
EntityConnectionStringBuilder entity = new EntityConnectionStringBuilder();
// entity.Name = "EntityBazaCRM";
entity.Metadata = @"res://*/Data.System.csdl|res://*/Data.System.ssdl|res://*/Data.System.msl";
entity.Provider = "System.Data.SqlClient";
entity.ProviderConnectionString = sqlBuilder.ToString();
connection = entity.ToString();
return connection;
}
我在.Designer.cs中抛出Unable to load the specified metadata resource.
异常。
/// <summary>
/// Initialize a new EntityBazaCRM object.
/// </summary>
public EntityBazaCRM(string connectionString) : base(connectionString, "EntityBazaCRM")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
如果我在我的Entity创建者中定义.Name,则会抛出另一个异常
"Other keywords are not allowed when the 'Name' keyword is specified." (System.ArgumentException) Exception Message = "Other keywords are not allowed when the 'Name' keyword is specified.", Exception Type = "System.ArgumentException"
我知道我错过了一些我必须改变的东西,以便自生成的代码使用新的连接字符串,但在哪里查找它?
答案 0 :(得分:26)
阅读this answers文章和this blog后,我改变了:
entity.Metadata = @"res://*/Data.System.csdl|res://*/Data.System.ssdl|res://*/Data.System.msl";
要:
entity.Metadata = "res://*/";
它有效: - )
答案 1 :(得分:0)