How to find metafiles created by EF in a class library?

I moved my Entity Framework 4 model to a class library. Meta files are created in \ bin \ Debug

What connection string do I use to search for metafiles in the class library? I tried:

  <add name="Models.DataModelConnectionString" 
connectionString="metadata=res://MyClassLibrary, 1.0.0.0, neutral,
 null/bin/Debug/Models.DataModel.csdl|res://MyClassLibrary, 1.0.0.0, neutral,
 null/bin/Debug/Models.DataModel.ssdl|res://MyClassLibrary, 1.0.0.0, neutral,
 null/bin/Debug/Models.DataModel.msl;provider=Devart.Data.Oracle;
....">

I still get the error "The specified metadata path is not valid."

Do I need to move metafiles to the root directory of the class library?

Edit I tried to use res://*/Models.DataModel.csdl, etc., but got the error "Could not load the specified metadata resource." instead

+2
source share
2 answers

, , CopyToOutputDirectory EmbedInOutputAssembly

res://*/Model.ssdl ..

+1

EF / (MyCompany.MyApp.Infra), , app.config web.config

. :

MyContext.cs MyCompany.MyApp.Infra.

namespace MyCompany.MyApp.Domain
{
    using System.Data.Objects;

    /// <summary>
    /// The MyContext
    /// </summary>
    public partial class MyContext : ObjectContext, IUnitOfWork
    {
        /// <summary>
        /// The ConnectionString
        /// </summary>
        public const string ConnectionString = "name=MyContext";

        /// <summary>
        /// The ContainerName
        /// </summary>
        public const string ContainerName = "MyContext";

        /// <summary>
        /// Initializes a new instance of the <see cref="MyContext"/> class.
        /// </summary>
        public MyContext()
            : base(ConnectionString, ContainerName)
        {
            this.ContextOptions.LazyLoadingEnabled = true;
        }
    }
}

web.config - Silverlight

<add name="MyContext"
connectionString="metadata=res://MyCompany.MyApp.Infra/DataModel.MyContext.csdl|
                           res://MyCompany.MyApp.Infra/DataModel.MyContext.ssdl|
                           res://MyCompany.MyApp.Infra/DataModel.MyContext.msl;
provider=System.Data.SqlClient;
provider connection string=&quot;Data Source=localhost\DB_01;Initial Catalog=MyDB;Persist Security Info=True;User ID=usr;Password=pwd;MultipleActiveResultSets=True&quot;"
providerName="System.Data.EntityClient"
/>
+2

Source: https://habr.com/ru/post/1747160/


All Articles