实体框架:无法加载指定的元数据资源 [英] Entity Framework: Unable to load the specified metadata resource

查看:106
本文介绍了实体框架:无法加载指定的元数据资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定将 Entity Connection String app.config 移动到代码中。但是设置完成后,如下所示:

I decided to move Entity Connection String from app.config to code. However after setting it up like this:

    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;
    }

我有一个异常抛出无法加载指定元数据资源 in .Designer.cs。

I have an exception thrown Unable to load the specified metadata resource. in .Designer.cs.

    /// <summary>
    /// Initialize a new EntityBazaCRM object.
    /// </summary>
    public EntityBazaCRM(string connectionString) : base(connectionString, "EntityBazaCRM")
    {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
    }

如果我在我的Entity创建者中定义.Name,它会抛出另一个异常

If I define .Name inside my Entity creator it throws another exception

当指定名称关键字时,不允许使用其他关键字。 (System.ArgumentException)异常消息=指定'名称'关键字时不允许使用其他关键字。,异常类型=System.ArgumentException

我知道我错过了一些我必须改变的东西,以便自我生成的代码使用新的连接字符串,但在哪里寻找?

I know I'm missing something that I have to change so that self generated code uses new connection string but where to look for it?

推荐答案

阅读此答案后文章和这个博客我改变了:

After reading this answers article and this blog I changed:

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

To:

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

它的工作原理是: - )

And it works :-)

这篇关于实体框架:无法加载指定的元数据资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆