gpt4 book ai didi

c# - Entity Framework : Unable to load the specified metadata resource

转载 作者:太空狗 更新时间:2023-10-29 20:45:03 29 4
gpt4 key购买 nike

我决定将 Entity Connection Stringapp.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();
}

如果我在实体创建器中定义 .Name,它会抛出另一个异常

“指定‘名称’关键字时不允许使用其他关键字。” (System.ArgumentException) Exception Message = "Other keywords are not allowed when the 'Name' keyword is specified.",异常类型 = "System.ArgumentException"

我知道我遗漏了一些必须更改的内容,以便自行生成的代码使用新的连接字符串,但在哪里寻找它?

最佳答案

看完this answers文章和this blog我改变了:

  entity.Metadata = @"res://*/Data.System.csdl|res://*/Data.System.ssdl|res://*/Data.System.msl";

收件人:

  entity.Metadata = "res://*/";

而且有效:-)

关于c# - Entity Framework : Unable to load the specified metadata resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8971698/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com