1

私は2つのプロジェクトを持っています

MyProject //MVC 3 app
MyProject.DAL //Class Library project type

内部MyProject.DALには、生成されたエンティティを含むフォルダーがありますEntityModels(EF Code-First アプローチ)。

namespace MyProject.DAL.EntityModels
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class myEntities : DbContext
    {
        public myEntities() : base("name=myEntities")
        {
             ...
        }
    }
}

app.config:

 <add name="myEntities" connectionString="metadata=res://*/EntityModels.DBMainModel.csdl|res://*/EntityModels.DBMainModel.ssdl|res://*/EntityModels.DBMainModel.msl;provider=..." providerName="System.Data.EntityClient" />

次に、プロジェクトでそのエンティティを使用したいMyProjectので、同じ接続文字列をファイルに追加しweb.configます。

しかし、私はUnable to load the specified metadata resource.エラーが発生します。web.config私はそのようないくつかの変更を加えてみました

<add name="myEntities"
connectionString="metadata=res://*/MyProject.DAL.EntityModels.DBMainModel.csdl|
                           res://*/MyProject.DAL.EntityModels.DBMainModel.ssdl|
                           res://*/MyProject.DAL.EntityModels.DBMainModel.msl;provider=..." providerName="System.Data.EntityClient" />

<add name="myEntities"
connectionString="metadata=res://MyProject.DAL.EntityModels.DBMainModel.csdl|
                           res://MyProject.DAL.EntityModels.DBMainModel.ssdl|
                           res://MyProject.DAL.EntityModels.DBMainModel.msl;provider=..." providerName="System.Data.EntityClient" />


<add name="myEntities"
connectionString="metadata=res://MyProject.DAL/EntityModels.DBMainModel.csdl|
                           res://MyProject.DAL/EntityModels.DBMainModel.ssdl|
                           res://MyProject.DAL/EntityModels.DBMainModel.msl;provider=..." providerName="System.Data.EntityClient" />

しかし、何も機能しません。それを修正する方法?

4

1 に答える 1

0

SqlClientコードファーストの場合は、純粋な connectionString 値を適切な .config ファイルに入れる必要があります ( notを扱っていますEntityClient)。
ConnectionString 値の詳細については、http://www.connectionstrings.com/sql-server/を参照してください。

SQL Server データベースの場合、基本的には次のようになります。

<add name="MyEntities" connectionString="Data Source=myServerName\myInstanceName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;" providerName="System.Data.SqlClient"/>
于 2013-10-31T12:14:39.937 に答える